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);
}
}
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;
}
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());
}
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;
}
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)"));
}
Aggregations