use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class CreateOperations method doCreate.
//
// Private helper methods
//
private CreateResponse doCreate(CreateRequest createRequest) throws IngestException, SourceUnavailableException {
CreateResponse createResponse;
Exception ingestError = null;
createRequest = queryOperations.setFlagsOnRequest(createRequest);
createRequest = validateCreateRequest(createRequest);
createRequest = validateLocalSource(createRequest);
String fileNames = "";
if (createRequest != null) {
List<String> fileList = createRequest.getMetacards().stream().filter(Objects::nonNull).map(Metacard::getTitle).collect(Collectors.toList());
fileNames = String.join(", ", fileList);
}
try {
INGEST_LOGGER.info("Started ingesting metacard with titles: {}.", fileNames);
createRequest = injectAttributes(createRequest);
createRequest = setDefaultValues(createRequest);
createRequest = processPreAuthorizationPlugins(createRequest);
createRequest = updateCreateRequestPolicyMap(createRequest);
createRequest = processPrecreateAccessPlugins(createRequest);
createRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.CREATE, Collections.emptyList()));
createRequest = processPreIngestPlugins(createRequest);
createRequest = validateCreateRequest(createRequest);
createResponse = getCreateResponse(createRequest);
createResponse = performRemoteCreate(createRequest, createResponse);
} catch (IngestException iee) {
ingestError = iee;
throw iee;
} catch (StopProcessingException see) {
ingestError = see;
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
ingestError = re;
throw new InternalIngestException("Exception during runtime while performing create", re);
} finally {
if (createRequest != null && ingestError != null && INGEST_LOGGER.isInfoEnabled()) {
INGEST_LOGGER.info("Error on create operation. {} metacards failed to ingest. {}", createRequest.getMetacards().size(), buildIngestLog(createRequest), ingestError);
}
}
try {
createResponse = validateFixCreateResponse(createResponse, createRequest);
} catch (RuntimeException re) {
LOGGER.info("Exception during runtime while performing doing post create operations (plugins and pubsub)", re);
}
if (createResponse == null) {
// suppress all npe findings for this method.
throw new IngestException("CatalogProvider returned null CreateResponse Object.");
}
return createResponse;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class QueryOperations method populateQueryResponsePolicyMap.
private QueryResponse populateQueryResponsePolicyMap(QueryResponse queryResponse) throws FederationException {
HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryResponse.getProperties());
for (Result result : queryResponse.getResults()) {
HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
try {
PolicyResponse policyResponse = plugin.processPostQuery(result, unmodifiableProperties);
opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
} catch (StopProcessingException e) {
throw new FederationException(QUERY_FAILURE_MSG, e);
}
}
result.getMetacard().setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
}
queryResponse.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
return queryResponse;
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class UpdateOperations method doUpdate.
//
// Private helper methods
//
private UpdateResponse doUpdate(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
updateRequest = queryOperations.setFlagsOnRequest(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
updateRequest = validateLocalSource(updateRequest);
try {
updateRequest = injectAttributes(updateRequest);
updateRequest = setDefaultValues(updateRequest);
updateRequest = populateMetacards(updateRequest);
updateRequest = processPreAuthorizationPlugins(updateRequest);
updateRequest = populateUpdateRequestPolicyMap(updateRequest);
updateRequest = processPreUpdateAccessPlugins(updateRequest);
updateRequest = processPreIngestPlugins(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
// Call the update on the catalog
LOGGER.debug("Calling catalog.update() with {} updates.", updateRequest.getUpdates().size());
UpdateResponse updateResponse = performLocalUpdate(updateRequest);
updateResponse = performRemoteUpdate(updateRequest, updateResponse);
// Handle the posting of messages to pubsub
updateResponse = validateFixUpdateResponse(updateResponse, updateRequest);
return updateResponse;
} catch (StopProcessingException see) {
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
LOGGER.debug("Unhandled runtime exception during update", re);
throw new InternalIngestException("Exception during runtime while performing update", re);
}
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class DeliveryProcessor method process.
public void process(Event event) {
String methodName = "process";
LOGGER.debug("ENTERING: {}", methodName);
Metacard entry = (Metacard) event.getProperty(PubSubConstants.HEADER_ENTRY_KEY);
String operation = event.getProperty(PubSubConstants.HEADER_OPERATION_KEY).toString();
LOGGER.debug("Delivering catalog entry.");
if (subscription != null) {
if (entry != null) {
if (operation.equalsIgnoreCase(PubSubConstants.CREATE)) {
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'created' entry with preDelivery plugin");
entry = plugin.processCreate(entry);
}
subscription.getDeliveryMethod().created(entry);
} catch (PluginExecutionException e) {
LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
subscription.getDeliveryMethod().created(entry);
} catch (StopProcessingException e) {
LOGGER.info(DELIVERY_FAILURE_MSG, e);
}
} else if (operation.equalsIgnoreCase(PubSubConstants.UPDATE)) {
// TODO: Handle hit or miss
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'updated' entry with preDelivery plugin");
Update updatedEntry = plugin.processUpdateHit(new UpdateImpl(entry, null));
entry = updatedEntry.getNewMetacard();
}
subscription.getDeliveryMethod().updatedHit(entry, entry);
} catch (PluginExecutionException e) {
LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
subscription.getDeliveryMethod().updatedHit(entry, entry);
} catch (StopProcessingException e) {
LOGGER.info(DELIVERY_FAILURE_MSG, e);
}
} else if (operation.equalsIgnoreCase(PubSubConstants.DELETE)) {
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'deleted' entry with preDelivery plugin");
entry = plugin.processCreate(entry);
}
subscription.getDeliveryMethod().deleted(entry);
} catch (PluginExecutionException e) {
LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
subscription.getDeliveryMethod().deleted(entry);
} catch (StopProcessingException e) {
LOGGER.info(DELIVERY_FAILURE_MSG, e);
}
} else {
LOGGER.debug("Could not deliver hit for subscription.");
}
} else {
LOGGER.debug("Could not deliver hit for subscription. Catalog entry is null.");
}
} else {
LOGGER.debug("Could not deliver hit for subscription. Subscription is null.");
}
LOGGER.debug("EXITING: {}", methodName);
}
use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.
the class OAuthPlugin method findExistingTokens.
/**
* Looks through the user's tokens to see if there are tokens from a different source connected to
* the same OAuth provider. The discovery URLs need to match. If a match is found an authorize
* source exception will be thrown so the user can authorize to query the new source instead of
* logging in.
*/
private void findExistingTokens(OAuthFederatedSource oauthSource, String sessionId, OIDCProviderMetadata metadata) throws StopProcessingException {
TokenInformation tokenInformation = tokenStorage.read(sessionId);
if (tokenInformation == null || !tokenInformation.getDiscoveryUrls().contains(oauthSource.getOauthDiscoveryUrl())) {
return;
}
// Verify that an unexpired token exists
List<TokenInformation.TokenEntry> matchingTokenEntries = tokenInformation.getTokenEntries().entrySet().stream().filter(entry -> !entry.getKey().equals(oauthSource.getId())).filter(entry -> entry.getValue().getDiscoveryUrl().equals(oauthSource.getOauthDiscoveryUrl())).map(Map.Entry::getValue).collect(Collectors.toList());
TokenInformation.TokenEntry tokenEntry = matchingTokenEntries.stream().filter(entry -> entry.getAccessToken() != null).filter(entry -> !isExpired(entry.getAccessToken())).findAny().orElse(null);
if (tokenEntry == null) {
// does one with a valid refresh token exist
tokenEntry = matchingTokenEntries.stream().filter(entry -> entry.getRefreshToken() != null).filter(entry -> !isExpired(entry.getRefreshToken())).findAny().orElse(null);
if (tokenEntry == null) {
return;
}
refreshTokens(tokenEntry.getRefreshToken(), oauthSource, sessionId, metadata);
}
LOGGER.debug("Unable to process query. The user needs to authorize to query the {} source.", oauthSource.getId());
Map<String, String> parameters = new HashMap<>();
parameters.put(SOURCE_ID, oauthSource.getId());
parameters.put(DISCOVERY_URL, oauthSource.getOauthDiscoveryUrl());
throw new OAuthPluginException(oauthSource.getId(), buildUrl(AUTHORIZE_SOURCE_ENDPOINT, parameters), AUTHORIZE_SOURCE_ENDPOINT, parameters, AUTH_SOURCE);
}
Aggregations