Search in sources :

Example 1 with StopProcessingException

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");
    }
}
Also used : ParserException(org.codice.ddf.parser.ParserException) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) StopProcessingException(ddf.catalog.plugin.StopProcessingException)

Example 2 with StopProcessingException

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;
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) StopProcessingException(ddf.catalog.plugin.StopProcessingException) UUID(java.util.UUID) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl)

Example 3 with StopProcessingException

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;
}
Also used : Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) HashMap(java.util.HashMap) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) PostFederatedQueryPlugin(ddf.catalog.plugin.PostFederatedQueryPlugin) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Future(java.util.concurrent.Future) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 4 with StopProcessingException

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);
}
Also used : ContentType(ddf.catalog.data.ContentType) QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) FederationStrategy(ddf.catalog.federation.FederationStrategy) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Date(java.util.Date) Test(org.junit.Test)

Example 5 with StopProcessingException

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;
}
Also used : StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(ddf.security.Subject)

Aggregations

StopProcessingException (ddf.catalog.plugin.StopProcessingException)38 QueryResponse (ddf.catalog.operation.QueryResponse)11 Metacard (ddf.catalog.data.Metacard)10 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)10 QueryRequest (ddf.catalog.operation.QueryRequest)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 Attribute (ddf.catalog.data.Attribute)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 Result (ddf.catalog.data.Result)6 Query (ddf.catalog.operation.Query)6 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)6 Source (ddf.catalog.source.Source)6 Map (java.util.Map)6 Subject (org.apache.shiro.subject.Subject)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 List (java.util.List)5