Search in sources :

Example 66 with IIdentifierFactory

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

the class BusinessCardServerAPI method getBusinessCard.

@Nonnull
public PD3BusinessCardType getBusinessCard(final String sServiceGroupID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /businesscard/" + sServiceGroupID;
    final String sAction = "getBusinessCard";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
        if (aServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
        }
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group
            throw new SMPNotFoundException("Unknown Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr == null) {
            throw new SMPBadRequestException("This SMP server does not support the Business Card API", m_aAPIProvider.getCurrentURI());
        }
        final ISMPBusinessCard aBusinessCard = aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(aServiceGroup);
        if (aBusinessCard == null) {
            // No such business card
            throw new SMPNotFoundException("No Business Card assigned to Service Group '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aBusinessCard.getAsJAXBObject();
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 67 with IIdentifierFactory

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

the class SMPServerAPI method saveServiceGroup.

public void saveServiceGroup(@Nonnull final String sPathServiceGroupID, @Nonnull final ServiceGroupType aServiceGroup, final boolean bCreateInSML, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + (bCreateInSML ? "" : CSMPServer.LOG_SUFFIX_NO_SML_INTERACTION);
    final String sAction = "saveServiceGroup";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aServiceGroup);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        // Parse the content of the payload with the same identifier factory to
        // ensure same case sensitivity
        final IParticipantIdentifier aPayloadServiceGroupID;
        if (aServiceGroup.getParticipantIdentifier() == null) {
            // Can happen when tampering with the input data
            aPayloadServiceGroupID = null;
        } else {
            aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceGroup.getParticipantIdentifier().getScheme(), aServiceGroup.getParticipantIdentifier().getValue());
        }
        if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
            // Business identifiers must be equal
            throw new SMPBadRequestException("Service Group Inconsistency. The URL points to '" + aPathServiceGroupID.getURIEncoded() + "' whereas the Service Group contains " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'"), m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final String sExtension = SMPExtensionConverter.convertToString(aServiceGroup.getExtension());
        if (aServiceGroupMgr.containsSMPServiceGroupWithID(aPathServiceGroupID))
            aServiceGroupMgr.updateSMPServiceGroup(aPathServiceGroupID, aSMPUser.getID(), sExtension);
        else
            aServiceGroupMgr.createSMPServiceGroup(aSMPUser.getID(), aPathServiceGroupID, sExtension, bCreateInSML);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
    } 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) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 68 with IIdentifierFactory

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

the class SMPServerAPI method deleteServiceRegistration.

public void deleteServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
    final String sAction = "deleteServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        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(sPathDocTypeID);
        if (aPathDocTypeID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
        final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
        if (aServiceInfo != null) {
            // Handle service information
            final EChange eChange = aServiceInfoMgr.deleteSMPServiceInformation(aServiceInfo);
            if (eChange.isUnchanged()) {
                // Most likely an internal error or an inconsistency
                throw new SMPNotFoundException("serviceInformation(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - ServiceInformation");
            STATS_COUNTER_SUCCESS.increment(sAction);
        } else {
            // No Service Info, so should be a redirect
            final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
            final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aPathDocTypeID);
            if (aRedirect != null) {
                // Handle redirect
                final EChange eChange = aRedirectMgr.deleteSMPRedirect(aRedirect);
                if (eChange.isUnchanged()) {
                    // Most likely an internal error or an inconsistency
                    throw new SMPNotFoundException("redirect(" + aPathServiceGroupID.getURIEncoded() + ", " + aPathDocTypeID.getURIEncoded() + ")", m_aAPIDataProvider.getCurrentURI());
                }
                if (LOGGER.isInfoEnabled())
                    LOGGER.info(sLog + " SUCCESS - Redirect");
                STATS_COUNTER_SUCCESS.increment(sAction);
            } else {
                // Neither redirect nor endpoint found
                throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
            }
        }
    } 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) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) EChange(com.helger.commons.state.EChange) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 69 with IIdentifierFactory

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

the class SMPServerAPI method deleteServiceRegistrations.

public void deleteServiceRegistrations(@Nonnull final String sPathServiceGroupID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "DELETE /" + sPathServiceGroupID + "/services/";
    final String sAction = "deleteServiceRegistrations";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aSMPUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aServiceGroup == null) {
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
        EChange eChange = aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aServiceGroup);
        final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
        eChange = eChange.or(aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aServiceGroup));
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS - " + eChange);
        STATS_COUNTER_SUCCESS.increment(sAction);
    } 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) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IUser(com.helger.photon.security.user.IUser) EChange(com.helger.commons.state.EChange) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException)

Example 70 with IIdentifierFactory

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

the class SMPBusinessCardManagerJDBC method getAllSMPBusinessCards.

@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPBusinessCard> getAllSMPBusinessCards() {
    final ICommonsList<ISMPBusinessCard> ret = new CommonsArrayList<>();
    final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT id, pid, name, country, geoinfo, identifiers, websites, contacts, addon, regdate" + " FROM smp_bce");
    if (aDBResult != null) {
        final IIdentifierFactory aIF = SMPMetaManager.getIdentifierFactory();
        // Group by ID
        final ICommonsMap<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntityMap = new CommonsHashMap<>();
        for (final DBResultRow aRow : aDBResult) {
            final SMPBusinessCardEntity aEntity = new SMPBusinessCardEntity(aRow.getAsString(0));
            // Single name only
            aEntity.names().add(new SMPBusinessCardName(aRow.getAsString(2), null));
            aEntity.setCountryCode(aRow.getAsString(3));
            aEntity.setGeographicalInformation(aRow.getAsString(4));
            aEntity.identifiers().setAll(getJsonAsBCI(aRow.getAsString(5)));
            aEntity.websiteURIs().setAll(getJsonAsString(aRow.getAsString(6)));
            aEntity.contacts().setAll(getJsonAsBCC(aRow.getAsString(7)));
            aEntity.setAdditionalInformation(aRow.getAsString(8));
            aEntity.setRegistrationDate(aRow.get(9).getAsLocalDate());
            aEntityMap.computeIfAbsent(aIF.parseParticipantIdentifier(aRow.getAsString(1)), k -> new CommonsArrayList<>()).add(aEntity);
        }
        // Convert
        for (final Map.Entry<IParticipantIdentifier, ICommonsList<SMPBusinessCardEntity>> aEntry : aEntityMap.entrySet()) {
            final IParticipantIdentifier aPID = aEntry.getKey();
            ret.add(new SMPBusinessCard(aPID, aEntry.getValue()));
        }
    }
    return ret;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) Nonnegative(javax.annotation.Nonnegative) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) LoggerFactory(org.slf4j.LoggerFactory) IJsonObject(com.helger.json.IJsonObject) EChange(com.helger.commons.state.EChange) IJsonWriterSettings(com.helger.json.serialize.IJsonWriterSettings) Supplier(java.util.function.Supplier) JsonWriterSettings(com.helger.json.serialize.JsonWriterSettings) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) CallbackList(com.helger.commons.callback.CallbackList) JsonArray(com.helger.json.JsonArray) AbstractJDBCEnabledManager(com.helger.db.jdbc.mgr.AbstractJDBCEnabledManager) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) MutableBoolean(com.helger.commons.mutable.MutableBoolean) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) Map(java.util.Map) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) JsonReader(com.helger.json.serialize.JsonReader) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) Collection(java.util.Collection) JsonObject(com.helger.json.JsonObject) ValueEnforcer(com.helger.commons.ValueEnforcer) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) AuditHelper(com.helger.photon.audit.AuditHelper) List(java.util.List) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJson(com.helger.json.IJson) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) SMPBusinessCard(com.helger.phoss.smp.domain.businesscard.SMPBusinessCard) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) 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)

Aggregations

IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)84 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)57 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)34 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)33 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)30 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)22 IUser (com.helger.photon.security.user.IUser)20 Nonnull (javax.annotation.Nonnull)19 Test (org.junit.Test)19 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)17 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)15 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)13 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)13 HCNodeList (com.helger.html.hc.impl.HCNodeList)11 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)11 Locale (java.util.Locale)11 Nullable (javax.annotation.Nullable)11 HCEdit (com.helger.html.hc.html.forms.HCEdit)10 RequestField (com.helger.photon.core.form.RequestField)10