Search in sources :

Example 66 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswSubscriptionConfigFactory method restore.

public void restore() {
    try (StringReader sr = new StringReader(filterXml)) {
        Unmarshaller unmarshaller = CswQueryFactory.getJaxBContext().createUnmarshaller();
        JAXBElement<GetRecordsType> jaxbElement = (JAXBElement<GetRecordsType>) unmarshaller.unmarshal(sr);
        GetRecordsType request = jaxbElement.getValue();
        if (!subscriptionService.hasSubscription(subscriptionId)) {
            subscriptionService.addOrUpdateSubscription(request, false);
        }
    } catch (JAXBException | CswException e) {
        LOGGER.info("Error restoring subscription: {} with delivery URL: {} XML: {}", new Object[] { subscriptionId, deliveryMethodUrl, filterXml }, e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 67 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswQueryFactory method buildFilter.

private CswRecordMapperFilterVisitor buildFilter(QueryConstraintType constraint) throws CswException {
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, metacardTypes);
    Filter filter = null;
    if (constraint != null) {
        if (constraint.isSetCqlText()) {
            try {
                filter = CQL.toFilter(constraint.getCqlText());
            } catch (CQLException e) {
                throw new CswException("Unable to parse CQL Constraint: " + e.getMessage(), e);
            }
        } else if (constraint.isSetFilter()) {
            FilterType constraintFilter = constraint.getFilter();
            filter = parseFilter(constraintFilter);
        }
    } else {
        // not supported by catalog:
        //filter = Filter.INCLUDE;
        filter = builder.attribute(Core.ID).is().like().text(FilterDelegate.WILDCARD_CHAR);
    }
    if (filter == null) {
        throw new CswException("Invalid Filter Expression", CswConstants.NO_APPLICABLE_CODE, null);
    }
    filter = transformCustomFunctionToFilter(filter);
    try {
        visitor.setVisitedFilter((Filter) filter.accept(visitor, new FilterFactoryImpl()));
    } catch (UnsupportedOperationException ose) {
        throw new CswException(ose.getMessage(), CswConstants.INVALID_PARAMETER_VALUE, null);
    }
    return visitor;
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswRecordMapperFilterVisitor(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 68 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswQueryFactory method buildSort.

private SortBy buildSort(SortByType sort) throws CswException {
    if (sort == null || sort.getSortProperty() == null) {
        return null;
    }
    SortBy[] sortByArr = parseSortBy(sort);
    if (sortByArr.length > 1) {
        LOGGER.debug("Query request has multiple sort criteria, only primary will be used");
    }
    SortBy sortBy = sortByArr[0];
    if (sortBy.getPropertyName() == null) {
        LOGGER.debug("No property name in primary sort criteria");
        return null;
    }
    if (!attributeRegistry.lookup(sortBy.getPropertyName().getPropertyName()).isPresent() && !DefaultCswRecordMap.hasDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext())) {
        throw new CswException("Property " + sortBy.getPropertyName().getPropertyName() + " is not a valid SortBy Field", CswConstants.INVALID_PARAMETER_VALUE, "SortProperty");
    }
    String name = DefaultCswRecordMap.getDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext());
    PropertyName propName = new AttributeExpressionImpl(new NameImpl(name));
    return new SortByImpl(propName, sortBy.getSortOrder());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) NameImpl(org.geotools.feature.NameImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)

Example 69 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswSubscriptionEndpoint method addOrUpdateSubscription.

public synchronized String addOrUpdateSubscription(GetRecordsType request, boolean persistSubscription) throws CswException {
    String methodName = "createSubscription";
    LOGGER.trace("ENTERING: {}    (persistSubscription = {})", methodName);
    if (request.getResponseHandler() == null || request.getResponseHandler().isEmpty() || StringUtils.isEmpty(request.getResponseHandler().get(0))) {
        throw new CswException("Unable to create subscription because deliveryMethodUrl is null or empty");
    }
    String deliveryMethodUrl = request.getResponseHandler().get(0);
    String subscriptionUuid = getSubscriptionUuid(request.getRequestId());
    LOGGER.debug("subscriptionUuid = {}", subscriptionUuid);
    request.setRequestId(subscriptionUuid);
    // to registry
    if (registeredSubscriptions.containsKey(subscriptionUuid)) {
        LOGGER.debug("Delete existing subscription {} for re-creation", subscriptionUuid);
        deleteCswSubscription(subscriptionUuid);
    }
    CswSubscription sub = createSubscription(request);
    Dictionary<String, String> props = new Hashtable<>();
    props.put("subscription-id", subscriptionUuid);
    props.put("event-endpoint", request.getResponseHandler().get(0));
    LOGGER.debug("Registering Subscription");
    ServiceRegistration serviceRegistration = getBundleContext().registerService(Subscription.class.getName(), sub, props);
    if (serviceRegistration != null) {
        LOGGER.debug("Subscription registered with bundle ID = {} ", serviceRegistration.getReference().getBundle().getBundleId());
        registeredSubscriptions.put(subscriptionUuid, serviceRegistration);
        // client originally provided.
        if (persistSubscription) {
            persistSubscription(sub, deliveryMethodUrl, subscriptionUuid);
        }
    } else {
        LOGGER.debug("Subscription registration failed");
    }
    LOGGER.trace("EXITING: {}", methodName);
    return subscriptionUuid;
}
Also used : Hashtable(java.util.Hashtable) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 70 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class TestCswResponseExceptionMapper method testEmptyCswException.

@Test
public void testEmptyCswException() {
    String exceptionReportXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" + "<ows:ExceptionReport version=\"1.2.0\" xmlns:ns16=\"http://www.opengis.net/ows/1.1\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cat=\"http://www.opengis.net/cat/csw\" xmlns:gco=\"http://www.isotc211.org/2005/gco\" xmlns:gmd=\"http://www.isotc211.org/2005/gmd\" xmlns:fra=\"http://www.cnig.gouv.fr/2005/fra\" xmlns:ins=\"http://www.inspire.org\" xmlns:gmx=\"http://www.isotc211.org/2005/gmx\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:dct=\"http://purl.org/dc/terms/\" xmlns:ows=\"http://www.opengis.net/ows\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:gmi=\"http://www.isotc211.org/2005/gmi\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + "</ows:ExceptionReport>";
    CswException cswException = createCswException(exceptionReportXml);
    assertThat(cswException.getMessage(), containsString("Empty Exception Report (version = 1.2.0)"));
}
Also used : CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)84 Test (org.junit.Test)55 CapabilitiesType (net.opengis.cat.csw.v_2_0_2.CapabilitiesType)19 GetCapabilitiesType (net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType)19 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QueryImpl (ddf.catalog.operation.impl.QueryImpl)13 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)13 DescribeRecordResponseType (net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType)13 Matchers.anyString (org.mockito.Matchers.anyString)13 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)10 ArrayList (java.util.ArrayList)10 SchemaComponentType (net.opengis.cat.csw.v_2_0_2.SchemaComponentType)10 GetCapabilitiesRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest)10 SourceResponse (ddf.catalog.operation.SourceResponse)9 IOException (java.io.IOException)9 DescribeRecordRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest)9 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)7 Filter (org.opengis.filter.Filter)7 JAXBException (javax.xml.bind.JAXBException)6