Search in sources :

Example 1 with CswSourceConfigurationField

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

the class CswServiceProperties method servicePropsToCswConfig.

public static final CswSourceConfigurationField servicePropsToCswConfig(Map<String, Object> props) {
    CswSourceConfigurationField cswConfig = new CswSourceConfigurationField();
    cswConfig.pid(mapValue(props, SERVICE_PID_KEY));
    cswConfig.sourceName(mapValue(props, ID));
    cswConfig.endpointUrl(mapValue(props, CSW_URL));
    cswConfig.credentials().username(mapValue(props, USERNAME));
    cswConfig.credentials().password(FLAG_PASSWORD);
    cswConfig.outputSchema(mapValue(props, OUTPUT_SCHEMA));
    cswConfig.spatialOperator(mapValue(props, FORCE_SPATIAL_FILTER));
    cswConfig.cswProfile(factoryPidToCswProfile(mapValue(props, FACTORY_PID_KEY)));
    return cswConfig;
}
Also used : CswSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.CswSourceConfigurationField)

Example 2 with CswSourceConfigurationField

use of org.codice.ddf.admin.sources.fields.type.CswSourceConfigurationField 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

CswSourceConfigurationField (org.codice.ddf.admin.sources.fields.type.CswSourceConfigurationField)2 XPath (javax.xml.xpath.XPath)1 ReportWithResultImpl (org.codice.ddf.admin.common.report.ReportWithResultImpl)1 SourceUtilCommons.createDocument (org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument)1 SourceConfigUnionField (org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField)1 Document (org.w3c.dom.Document)1