Search in sources :

Example 1 with SMPServiceInformation

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

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

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

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

the class SMPServiceInformationManagerXML method deleteSMPProcess.

@Nonnull
public EChange deleteSMPProcess(@Nullable final ISMPServiceInformation aSMPServiceInformation, @Nullable final ISMPProcess aProcess) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPProcess (" + aSMPServiceInformation + ", " + aProcess + ")");
    if (aSMPServiceInformation == null || aProcess == null) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPProcess - failure");
        return EChange.UNCHANGED;
    }
    // Find implementation object
    final SMPServiceInformation aRealServiceInformation = getOfID(aSMPServiceInformation.getID());
    if (aRealServiceInformation == null) {
        AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aSMPServiceInformation.getID(), "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPProcess - failure - no such service information");
        return EChange.UNCHANGED;
    }
    m_aRWLock.writeLock().lock();
    try {
        // Main deletion in write lock
        if (aRealServiceInformation.deleteProcess(aProcess).isUnchanged()) {
            AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aProcess.getProcessIdentifier().getURIEncoded(), "no-such-process");
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("deleteSMPProcess - failure - no such process");
            return EChange.UNCHANGED;
        }
        // Save changes
        internalUpdateItem(aRealServiceInformation);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID(), aProcess.getProcessIdentifier().getURIEncoded());
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPProcess - success");
    return EChange.CHANGED;
}
Also used : SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) Nonnull(javax.annotation.Nonnull)

Example 5 with SMPServiceInformation

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

the class SMPServerAPI method saveServiceRegistration.

@Nonnull
public ESuccess saveServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + "/services/" + sPathDocumentTypeID;
    final String sAction = "saveServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aServiceMetadata);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        // Parse provided identifiers
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocumentTypeID);
        if (aPathDocTypeID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseDocType(sPathDocumentTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // May be null for a Redirect!
        final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
        if (aServiceInformation != null) {
            // metadata (body) must equal path
            if (aServiceInformation.getParticipantIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata has inconsistent values.\n" + "Service Information Participant ID: <none>\n" + "URL Parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IParticipantIdentifier aPayloadServiceGroupID;
            if (aServiceInformation.getParticipantIdentifier() == null) {
                // Can happen when tampering with the input data
                aPayloadServiceGroupID = null;
            } else {
                aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceInformation.getParticipantIdentifier().getScheme(), aServiceInformation.getParticipantIdentifier().getValue());
            }
            if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
                // Participant ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Infoformation Participant ID: " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'") + "\n" + "URL parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            if (aServiceInformation.getDocumentIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: <none>\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IDocumentTypeIdentifier aPayloadDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(aServiceInformation.getDocumentIdentifier().getScheme(), aServiceInformation.getDocumentIdentifier().getValue());
            if (!aPathDocTypeID.hasSameContent(aPayloadDocTypeID)) {
                // Document type ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: '" + aPayloadDocTypeID.getURIEncoded() + "'\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
        }
        // Main save
        final IUser aDataUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aDataUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aPathServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            // Service group not found
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        if (aServiceMetadata.getRedirect() != null) {
            // Handle redirect
            final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
            // not available in Peppol mode
            final X509Certificate aCertificate = null;
            if (aRedirectMgr.createOrUpdateSMPRedirect(aPathServiceGroup, aPathDocTypeID, aServiceMetadata.getRedirect().getHref(), aServiceMetadata.getRedirect().getCertificateUID(), aCertificate, SMPExtensionConverter.convertToString(aServiceMetadata.getRedirect().getExtension())) == null) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - Redirect");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - Redirect");
        } else if (aServiceInformation != null) {
            // Handle service information
            final ProcessListType aJAXBProcesses = aServiceInformation.getProcessList();
            final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
            for (final ProcessType aJAXBProcess : aJAXBProcesses.getProcess()) {
                final ICommonsList<SMPEndpoint> aEndpoints = new CommonsArrayList<>();
                for (final EndpointType aJAXBEndpoint : aJAXBProcess.getServiceEndpointList().getEndpoint()) {
                    final SMPEndpoint aEndpoint = new SMPEndpoint(aJAXBEndpoint.getTransportProfile(), W3CEndpointReferenceHelper.getAddress(aJAXBEndpoint.getEndpointReference()), aJAXBEndpoint.isRequireBusinessLevelSignature(), aJAXBEndpoint.getMinimumAuthenticationLevel(), aJAXBEndpoint.getServiceActivationDate(), aJAXBEndpoint.getServiceExpirationDate(), aJAXBEndpoint.getCertificate(), aJAXBEndpoint.getServiceDescription(), aJAXBEndpoint.getTechnicalContactUrl(), aJAXBEndpoint.getTechnicalInformationUrl(), SMPExtensionConverter.convertToString(aJAXBEndpoint.getExtension()));
                    aEndpoints.add(aEndpoint);
                }
                final SMPProcess aProcess = new SMPProcess(SimpleProcessIdentifier.wrap(aJAXBProcess.getProcessIdentifier()), aEndpoints, SMPExtensionConverter.convertToString(aJAXBProcess.getExtension()));
                aProcesses.add(aProcess);
            }
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final String sExtensionXML = SMPExtensionConverter.convertToString(aServiceInformation.getExtension());
            if (aServiceInfoMgr.mergeSMPServiceInformation(new SMPServiceInformation(aPathServiceGroup, aPathDocTypeID, aProcesses, sExtensionXML)).isFailure()) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - ServiceInformation");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - ServiceInformation");
        } else {
            throw new SMPBadRequestException("Save Service Metadata was called with neither a Redirect nor a ServiceInformation", m_aAPIDataProvider.getCurrentURI());
        }
        if (false)
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return ESuccess.SUCCESS;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) 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) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) X509Certificate(java.security.cert.X509Certificate) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) IUser(com.helger.photon.security.user.IUser) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation)13 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)11 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)11 Nonnull (javax.annotation.Nonnull)11 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)10 SMPProcess (com.helger.phoss.smp.domain.serviceinfo.SMPProcess)10 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)9 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)9 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)8 ICommonsList (com.helger.commons.collection.impl.ICommonsList)8 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)8 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)7 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)7 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)7 ValueEnforcer (com.helger.commons.ValueEnforcer)6 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)6 CallbackList (com.helger.commons.callback.CallbackList)6 EqualsHelper (com.helger.commons.equals.EqualsHelper)6