use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class CswEndpoint method queryCsw.
private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
if (LOGGER.isDebugEnabled()) {
try {
Writer writer = new StringWriter();
try {
Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
marshaller.marshal(jaxbElement, writer);
} catch (JAXBException e) {
LOGGER.debug("Unable to marshall {} to XML. Exception {}", GetRecordsType.class, e);
}
LOGGER.debug(writer.toString());
} catch (Exception e) {
LOGGER.debug("Unable to create debug message for getRecordsType: {}", e);
}
}
QueryType query = (QueryType) request.getAbstractQuery().getValue();
CswRecordCollection response = new CswRecordCollection();
response.setRequest(request);
response.setOutputSchema(request.getOutputSchema());
response.setMimeType(request.getOutputFormat());
response.setElementName(query.getElementName());
response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
QueryRequest queryRequest = queryFactory.getQuery(request);
try {
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
LOGGER.debug("Attempting to execute query: {}", queryRequest);
QueryResponse queryResponse = framework.query(queryRequest);
response.setSourceResponse(queryResponse);
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.debug("Unable to query", e);
throw new CswException(e);
}
}
return response;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class CswEndpoint method transaction.
@Override
@POST
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
public TransactionResponseType transaction(CswTransactionRequest request) throws CswException {
if (request == null) {
throw new CswException("TransactionRequest request is null");
}
TransactionResponseType response = new TransactionResponseType();
TransactionSummaryType summary = new TransactionSummaryType();
summary.setTotalInserted(BigInteger.valueOf(0));
summary.setTotalUpdated(BigInteger.valueOf(0));
summary.setTotalDeleted(BigInteger.valueOf(0));
response.setTransactionSummary(summary);
response.setVersion(CswConstants.VERSION_2_0_2);
int numInserted = 0;
for (InsertAction insertAction : request.getInsertActions()) {
CreateRequest createRequest = new CreateRequestImpl(insertAction.getRecords());
try {
CreateResponse createResponse = framework.create(createRequest);
if (request.isVerbose()) {
response.getInsertResult().add(getInsertResultFromResponse(createResponse));
}
numInserted += createResponse.getCreatedMetacards().size();
} catch (IngestException | SourceUnavailableException e) {
throw new CswException("Unable to insert record(s).", CswConstants.TRANSACTION_FAILED, insertAction.getHandle());
}
}
LOGGER.debug("{} records inserted.", numInserted);
response.getTransactionSummary().setTotalInserted(BigInteger.valueOf(numInserted));
int numUpdated = 0;
for (UpdateAction updateAction : request.getUpdateActions()) {
try {
numUpdated += updateRecords(updateAction);
} catch (CswException | FederationException | IngestException | SourceUnavailableException | UnsupportedQueryException e) {
throw new CswException("Unable to update record(s).", CswConstants.TRANSACTION_FAILED, updateAction.getHandle());
}
}
LOGGER.debug("{} records updated.", numUpdated);
response.getTransactionSummary().setTotalUpdated(BigInteger.valueOf(numUpdated));
int numDeleted = 0;
for (DeleteAction deleteAction : request.getDeleteActions()) {
try {
numDeleted += deleteRecords(deleteAction);
} catch (CswException | FederationException | IngestException | SourceUnavailableException | UnsupportedQueryException e) {
throw new CswException("Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, deleteAction.getHandle());
}
}
LOGGER.debug("{} records deleted.", numDeleted);
response.getTransactionSummary().setTotalDeleted(BigInteger.valueOf(numDeleted));
return response;
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class CswEndpoint method queryById.
private CswRecordCollection queryById(List<String> ids, String outputSchema) throws CswException {
QueryRequest queryRequest = queryFactory.getQueryById(ids);
try {
CswRecordCollection response = new CswRecordCollection();
response.setById(true);
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, outputSchema);
QueryResponse queryResponse = framework.query(queryRequest);
response.setSourceResponse(queryResponse);
List<Metacard> metacards = new LinkedList<>();
for (Result result : queryResponse.getResults()) {
metacards.add(result.getMetacard());
}
response.setCswRecords(metacards);
return response;
} catch (FederationException | SourceUnavailableException | UnsupportedQueryException e) {
throw new CswException(e);
}
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class TestRegistryStore method testInit.
@Test
public void testInit() throws Exception {
RegistryStoreImpl registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {
@Override
protected void validateOperation() {
}
@Override
public boolean isAvailable() {
return availability;
}
@Override
protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
if (queryResults == null) {
throw new UnsupportedQueryException("Test - Bad Query");
}
return new SourceResponseImpl(queryRequest, queryResults);
}
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
return new SourceResponseImpl(request, Collections.singletonList(new Result() {
@Override
public Metacard getMetacard() {
MetacardImpl metacard = new MetacardImpl();
metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "registryId");
metacard.setAttribute(Metacard.TITLE, "title");
return metacard;
}
@Override
public Double getRelevanceScore() {
return null;
}
@Override
public Double getDistanceInMeters() {
return null;
}
}));
}
@Override
protected CapabilitiesType getCapabilities() {
return mock(CapabilitiesType.class);
}
@Override
public void configureCswSource() {
}
;
@Override
protected Subject getSystemSubject() {
return subject;
}
@Override
BundleContext getBundleContext() {
return context;
}
});
registryStore.setFilterBuilder(filterBuilder);
registryStore.setFilterAdapter(filterAdapter);
registryStore.setConfigAdmin(configAdmin);
registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
registryStore.setSchemaTransformerManager(transformer);
registryStore.setAutoPush(true);
registryStore.setRegistryUrl("http://test.url:0101/example");
properties = new Hashtable<>();
properties.put(RegistryStoreImpl.ID, "registryId");
registryStore.setMetacardMarshaller(marshaller);
Csw csw = mock(Csw.class);
when(factory.getClientForSubject(any())).thenReturn(csw);
cswSourceConfiguration.setCswUrl("https://localhost");
cswSourceConfiguration.setPollIntervalMinutes(1);
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.init();
assertThat(registryStore.getRegistryId(), is("registryId"));
}
use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.
the class ResourceCacheService method queryForMetacard.
private Optional<Metacard> queryForMetacard(String metacardId) {
Filter filter = frameworkProperties.getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(metacardId);
QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter), true);
QueryResponse queryResponse = null;
try {
queryResponse = catalogFramework.query(queryRequest);
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Unable to lookup metacard for metacard id [{}].", metacardId);
return Optional.empty();
}
return queryResponse != null && queryResponse.getResults().size() == 1 ? Optional.of(queryResponse.getResults().get(0).getMetacard()) : Optional.empty();
}
Aggregations