use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class IdentificationPlugin method updateIdentifiers.
private void updateIdentifiers(Metacard metacard, boolean create) throws StopProcessingException {
boolean extOriginFound = false;
boolean extRegIdFound = false;
String metacardID = metacard.getId();
String registryID = RegistryUtility.getRegistryId(metacard);
String systemRegId = System.getProperty(RegistryConstants.REGISTRY_ID_PROPERTY);
try {
RegistryPackageType registryPackage = metacardMarshaller.getRegistryPackageFromMetacard(metacard);
List<ExternalIdentifierType> extIdList = new ArrayList<>();
//check if external ids are already present
if (registryPackage.isSetExternalIdentifier()) {
List<ExternalIdentifierType> currentExtIdList = registryPackage.getExternalIdentifier();
for (ExternalIdentifierType extId : currentExtIdList) {
extId.setRegistryObject(registryID);
if (extId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_LOCAL)) {
if (isInternal(metacard) && create) {
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_METACARD_ID, extId.getValue()));
}
extId.setValue(metacardID);
} else if (extId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN)) {
extOriginFound = true;
} else if (extId.getId().equals(RegistryConstants.REGISTRY_ID_ORIGIN)) {
if (!systemRegId.equals(extId.getValue()) && isInternal(metacard)) {
metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REMOTE_REGISTRY_ID, extId.getValue()));
}
extId.setValue(systemRegId);
extRegIdFound = true;
}
extIdList.add(extId);
}
if (!extOriginFound) {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
}
if (!extRegIdFound) {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_ID_CLASS, systemRegId));
}
} else {
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_LOCAL, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_METACARD_ID_CLASS, metacardID));
extIdList.add(createExternalIdentifier(RegistryConstants.REGISTRY_ID_ORIGIN, registryID, RegistryConstants.REGISTRY_ID_CLASS, systemRegId));
}
registryPackage.setExternalIdentifier(extIdList);
metacardMarshaller.setMetacardRegistryPackage(metacard, registryPackage);
} catch (ParserException e) {
throw new StopProcessingException("Unable to access Registry Metadata. Parser exception caught");
}
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class QueryMonitorPluginImpl method process.
/**
* Method that is implemented for {@link PostFederatedQueryPlugin}. Uses the given {@link QueryResponse} information
* to remove the {@link ActiveSearch} from the {@link ActiveSearch} {@link Map}.
*
* @param input {@link QueryResponse} that corresponds to response from the source that was queried
* by the user's original {@link QueryRequest}
* @return {@link QueryResponse} that was given as a parameter
*/
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
if (!removeSearchAfterComplete) {
LOGGER.debug("Not removing active search from map due to catalog:removeSearchAfterComplete false. To enable removing searches as searches finish, use command catalog:removesearchaftercomplete true.");
return input;
}
if (input == null) {
LOGGER.debug("Cannot remove ActiveSearch from the ActiveSearch Map. QueryResponse received in QueryMonitorPluginImpl was null.");
return null;
}
if (!removeActiveSearch((UUID) input.getRequest().getPropertyValue(SEARCH_ID))) {
QueryResponseImpl queryResponse = new QueryResponseImpl(input.getRequest(), new ArrayList<>(), 0);
queryResponse.closeResultQueue();
Set<ProcessingDetails> processingDetails = Collections.singleton(new ProcessingDetailsImpl(QueryMonitorPlugin.class.getCanonicalName(), new StopProcessingException("Query was cancelled by administrator")));
queryResponse.setProcessingDetails(processingDetails);
return queryResponse;
}
return input;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class AbstractFederationStrategy method federate.
@Override
public QueryResponse federate(List<Source> sources, final QueryRequest queryRequest) {
final String methodName = "federate";
LOGGER.trace("ENTERING: {}", methodName);
if (LOGGER.isDebugEnabled()) {
for (Source source : sources) {
if (source != null) {
LOGGER.debug("source to query: {}", source.getId());
}
}
}
Query originalQuery = queryRequest.getQuery();
int offset = originalQuery.getStartIndex();
final int pageSize = originalQuery.getPageSize();
// limit offset to max value
if (offset > this.maxStartIndex) {
offset = this.maxStartIndex;
}
final QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, null);
Map<Source, Future<SourceResponse>> futures = new HashMap<Source, Future<SourceResponse>>();
Query modifiedQuery = getModifiedQuery(originalQuery, sources.size(), offset, pageSize);
QueryRequest modifiedQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
// Do NOT call source.isAvailable() when checking sources
for (final Source source : sources) {
if (source != null) {
if (!futures.containsKey(source)) {
LOGGER.debug("running query on source: {}", source.getId());
try {
for (PreFederatedQueryPlugin service : preQuery) {
try {
modifiedQueryRequest = service.process(source, modifiedQueryRequest);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PreFederatedQueryPlugin: ", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing: ", e);
}
futures.put(source, queryExecutorService.submit(new CallableSourceResponse(source, modifiedQueryRequest.getQuery(), modifiedQueryRequest.getProperties())));
} else {
LOGGER.info("Duplicate source found with name {}. Ignoring second one.", source.getId());
}
}
}
QueryResponseImpl offsetResults = null;
// OffsetResultHandler does.
if (offset > 1 && sources.size() > 1) {
offsetResults = new QueryResponseImpl(queryRequest, null);
queryExecutorService.submit(new OffsetResultHandler(queryResponseQueue, offsetResults, pageSize, offset));
}
queryExecutorService.submit(createMonitor(queryExecutorService, futures, queryResponseQueue, modifiedQueryRequest.getQuery()));
QueryResponse queryResponse = null;
if (offset > 1 && sources.size() > 1) {
queryResponse = offsetResults;
LOGGER.debug("returning offsetResults");
} else {
queryResponse = queryResponseQueue;
LOGGER.debug("returning returnResults: {}", queryResponse);
}
try {
for (PostFederatedQueryPlugin service : postQuery) {
try {
queryResponse = service.process(queryResponse);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PostFederatedQueryPlugin: ", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing: ", e);
}
LOGGER.debug("returning Query Results: {}", queryResponse);
LOGGER.trace("EXITING: {}.federate", CLASS_NAME);
return queryResponse;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class CatalogFrameworkImplTest method testPreQueryStopExecution.
@Test(expected = FederationException.class)
public void testPreQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
FederationStrategy federationStrategy = mock(FederationStrategy.class);
QueryRequest request = mock(QueryRequest.class);
when(request.getQuery()).thenReturn(mock(Query.class));
PreQueryPlugin stopQueryPlugin = new PreQueryPlugin() {
@Override
public QueryRequest process(QueryRequest input) throws PluginExecutionException, StopProcessingException {
throw new StopProcessingException("Testing that the framework will stop the query.");
}
};
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setPreQuery(Arrays.asList(stopQueryPlugin));
frameworkProperties.setFederationStrategy(federationStrategy);
frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
CatalogFrameworkImpl framework = createFramework(frameworkProperties);
framework.query(request);
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class MetacardValidityFilterPlugin method getSubject.
private Subject getSubject(Request input) throws StopProcessingException {
Object securityAssertion = input.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
Subject subject;
if (securityAssertion instanceof Subject) {
subject = (Subject) securityAssertion;
LOGGER.debug("Filter plugin found Subject for query response.");
} else {
throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
}
return subject;
}
Aggregations