Search in sources :

Example 1 with SourceConfigUnionField

use of org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField in project admin-console-beta by connexta.

the class OpenSearchSourceUtils method getOpenSearchConfig.

/**
     * Attempts to create an OpenSearch configuration with the provided URL and credentials. If a configuration
     * is not found or created, the {@link ReportWithResultImpl}'s will have errors.
     *
     * @param urlField The URL to probe for OpenSearch capabilities
     * @param creds    optional credentials to send with Basic Auth header
     * @return a {@link ReportWithResultImpl} containing the {@link SourceConfigUnionField} or containing {@link org.codice.ddf.admin.common.report.message.ErrorMessage}s on failure.
     */
public ReportWithResultImpl<SourceConfigUnionField> getOpenSearchConfig(UrlField urlField, CredentialsField creds) {
    ReportWithResultImpl<SourceConfigUnionField> configResult = new ReportWithResultImpl<>();
    configResult.addMessages(verifyOpenSearchCapabilities(urlField, creds));
    if (configResult.containsErrorMsgs()) {
        return configResult;
    }
    OpenSearchSourceConfigurationField config = new OpenSearchSourceConfigurationField();
    config.endpointUrl(urlField.getValue()).credentials().username(creds.username()).password(FLAG_PASSWORD);
    configResult.result(config);
    return configResult;
}
Also used : ReportWithResultImpl(org.codice.ddf.admin.common.report.ReportWithResultImpl) OpenSearchSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.OpenSearchSourceConfigurationField) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField)

Example 2 with SourceConfigUnionField

use of org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField in project admin-console-beta by connexta.

the class SourceUtilCommons method getSourceConfigurations.

/**
     * Gets the configurations for the given factoryPids using the {@link ConfiguratorFactory}. A mapper is used
     * to transform the service properties to a {@link SourceConfigUnionField}. Providing the pid parameter
     * will return only the configuration with that pid.
     *
     * @param factoryPids factory pids to lookup configurations for
     * @param mapper a {@link Function} taking a map of string to objects and returning a {@code SourceConfigUnionField}
     * @param pid a servicePid to select a single configuration, returns all configs when null or empty
     * @return a list of {@code SourceInfoField}s configured in the system
     */
public static ListField<SourceInfoField> getSourceConfigurations(List<String> factoryPids, Function<Map<String, Object>, SourceConfigUnionField> mapper, String pid, ConfiguratorFactory configuratorFactory) {
    ListFieldImpl<SourceInfoField> sourceInfoListField = new ListFieldImpl<>(SourceInfoField.class);
    ConfigReader configReader = configuratorFactory.getConfigReader();
    if (StringUtils.isNotEmpty(pid)) {
        SourceConfigUnionField config = mapper.apply(configReader.getConfig(pid));
        sourceInfoListField.add(createSourceInfoField(true, config));
        populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
        return sourceInfoListField;
    }
    factoryPids.stream().flatMap(factoryPid -> configReader.getManagedServiceConfigs(factoryPid).values().stream()).map(mapper).forEach(config -> sourceInfoListField.add(createSourceInfoField(false, config)));
    populateSourceAvailability(sourceInfoListField.getList(), configuratorFactory);
    return sourceInfoListField;
}
Also used : ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField) SourceInfoField(org.codice.ddf.admin.sources.fields.SourceInfoField)

Example 3 with SourceConfigUnionField

use of org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField in project admin-console-beta by connexta.

the class WfsSourceUtils method getPreferredWfsConfig.

/**
     * Attempts to create a WFS configuration from the given url.
     *
     * Possible Error Codes to be returned
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNAUTHORIZED}
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNKNOWN_ENDPOINT}
     *
     * @param urlField WFS URL to probe for a configuration
     * @param creds    optional username to add to Basic Auth header
     * @return a {@link ReportWithResultImpl} containing the preferred {@link SourceConfigUnionField}, or containing {@link org.codice.ddf.admin.common.report.message.ErrorMessage}s on failure.
     */
public ReportWithResultImpl<SourceConfigUnionField> getPreferredWfsConfig(UrlField urlField, CredentialsField creds) {
    ReportWithResultImpl<String> responseBodyResult = requestUtils.sendGetRequest(urlField, creds, GET_CAPABILITIES_PARAMS);
    ReportWithResultImpl<SourceConfigUnionField> configResult = new ReportWithResultImpl<>();
    if (responseBodyResult.containsErrorMsgs()) {
        configResult.addMessages(responseBodyResult);
        return configResult;
    }
    String requestBody = responseBodyResult.result();
    Document capabilitiesXml;
    try {
        capabilitiesXml = createDocument(requestBody);
    } catch (Exception e) {
        LOGGER.debug("Failed to read response from WFS endpoint.");
        configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
        return configResult;
    }
    WfsSourceConfigurationField preferredConfig = new WfsSourceConfigurationField();
    preferredConfig.endpointUrl(urlField.getValue()).credentials().username(creds.username()).password(FLAG_PASSWORD);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(SOURCES_NAMESPACE_CONTEXT);
    String wfsVersion;
    try {
        wfsVersion = xpath.compile(WFS_VERSION_EXP).evaluate(capabilitiesXml);
    } catch (XPathExpressionException e) {
        LOGGER.debug("Failed to parse XML response.");
        configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
        return configResult;
    }
    try {
        configResult.result(preferredConfig.wfsVersion(wfsVersion));
    } catch (IllegalArgumentException e) {
        configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
    }
    return configResult;
}
Also used : XPath(javax.xml.xpath.XPath) ReportWithResultImpl(org.codice.ddf.admin.common.report.ReportWithResultImpl) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField) Document(org.w3c.dom.Document) SourceUtilCommons.createDocument(org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument) WfsSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 4 with SourceConfigUnionField

use of org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField in project admin-console-beta by connexta.

the class CswSourceUtils method getPreferredCswConfig.

/**
     * Attempts to create a CSW configuration from the given url.
     *
     * Possible Error Codes to be returned
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNAUTHORIZED}
     * - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNKNOWN_ENDPOINT}
     *
     * @param urlField A URL of an endpoint with CSW capabilities
     * @param creds    optional credentials for basic authentication
     * @return a {@link ReportWithResultImpl} containing the {@link SourceConfigUnionField} or an {@link org.codice.ddf.admin.common.report.message.ErrorMessage} on failure.
     */
public ReportWithResultImpl<SourceConfigUnionField> getPreferredCswConfig(UrlField urlField, CredentialsField creds) {
    ReportWithResultImpl<String> responseBodyResult = requestUtils.sendGetRequest(urlField, creds, GET_CAPABILITIES_PARAMS);
    ReportWithResultImpl<SourceConfigUnionField> configResult = new ReportWithResultImpl<>();
    if (responseBodyResult.containsErrorMsgs()) {
        configResult.addMessages(responseBodyResult);
        return configResult;
    }
    String requestBody = responseBodyResult.result();
    Document capabilitiesXml;
    try {
        capabilitiesXml = createDocument(requestBody);
    } catch (Exception e) {
        LOGGER.debug("Failed to create XML document from response.");
        configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
        return configResult;
    }
    CswSourceConfigurationField preferred = new CswSourceConfigurationField();
    preferred.endpointUrl(urlField.getValue()).credentials().username(creds.username()).password(FLAG_PASSWORD);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(SOURCES_NAMESPACE_CONTEXT);
    try {
        if ((Boolean) xpath.compile(HAS_CATALOG_METACARD_EXP).evaluate(capabilitiesXml, XPathConstants.BOOLEAN)) {
            configResult.result(preferred.outputSchema(METACARD_OUTPUT_SCHEMA).cswProfile(CSW_FEDERATION_PROFILE_SOURCE));
            return configResult;
        }
    } catch (Exception e) {
        LOGGER.debug("Failed to compile DDF Profile CSW discovery XPath expression.");
    }
    try {
        if ((Boolean) xpath.compile(HAS_GMD_ISO_EXP).evaluate(capabilitiesXml, XPathConstants.BOOLEAN)) {
            configResult.result(preferred.outputSchema(GMD_OUTPUT_SCHEMA).cswProfile(GMD_CSW_ISO_FEDERATED_SOURCE));
            return configResult;
        }
    } catch (Exception e) {
        LOGGER.debug("Failed to compile GMD CSW discovery XPath expression.");
    }
    try {
        xpath.compile(GET_FIRST_OUTPUT_SCHEMA).evaluate(capabilitiesXml);
        configResult.result(preferred.outputSchema(CSW_2_0_2_OUTPUT_SCHEMA).cswProfile(CSW_SPEC_PROFILE_FEDERATED_SOURCE));
        return configResult;
    } catch (Exception e) {
        LOGGER.debug("Failed to compile generic CSW specification discovery XPath expression.");
    }
    LOGGER.debug("URL [{}] responded to GetCapabilities request, but response was not readable.", urlField.getValue());
    configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
    return configResult;
}
Also used : XPath(javax.xml.xpath.XPath) ReportWithResultImpl(org.codice.ddf.admin.common.report.ReportWithResultImpl) CswSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.CswSourceConfigurationField) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField) Document(org.w3c.dom.Document) SourceUtilCommons.createDocument(org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument)

Aggregations

SourceConfigUnionField (org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField)4 ReportWithResultImpl (org.codice.ddf.admin.common.report.ReportWithResultImpl)3 XPath (javax.xml.xpath.XPath)2 SourceUtilCommons.createDocument (org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument)2 Document (org.w3c.dom.Document)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 ListFieldImpl (org.codice.ddf.admin.common.fields.base.ListFieldImpl)1 ConfigReader (org.codice.ddf.admin.configurator.ConfigReader)1 SourceInfoField (org.codice.ddf.admin.sources.fields.SourceInfoField)1 CswSourceConfigurationField (org.codice.ddf.admin.sources.fields.type.CswSourceConfigurationField)1 OpenSearchSourceConfigurationField (org.codice.ddf.admin.sources.fields.type.OpenSearchSourceConfigurationField)1 WfsSourceConfigurationField (org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField)1