예제 #1
0
 private ProcessingDetailsImpl createUnavailableProcessingDetails(Source source) {
   ProcessingDetailsImpl exception = new ProcessingDetailsImpl();
   SourceUnavailableException sue =
       new SourceUnavailableException(
           "Source \"" + source.getId() + "\" is unavailable and will not be queried");
   exception.setException(sue);
   exception.setSourceId(source.getId());
   if (LOGGER.isDebugEnabled()) {
     LOGGER.debug("Source Unavailable", sue);
   }
   return exception;
 }
  @Test
  public void testEmptyConfigurationsSource() throws IOException, InvalidSyntaxException {
    configureActionProvider();
    actionProvider.setConfigurationAdmin(configurationAdmin);
    Configuration[] configurations = new Configuration[0];

    when(source.getId()).thenReturn(SAMPLE_SOURCE_ID);
    when(configurationAdmin.listConfigurations(String.format("(id=%s)", SAMPLE_SOURCE_ID)))
        .thenReturn(configurations);

    List<Action> actions = actionProvider.getActions(source);

    assertThat(actions.size(), is(0));
  }
예제 #3
0
    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public void run() {
      String methodName = "run";
      logger.entry(methodName);

      SortBy sortBy = query.getSortBy();
      // Prepare the Comparators that we will use
      Comparator<Result> coreComparator = DEFAULT_COMPARATOR;

      if (sortBy != null && sortBy.getPropertyName() != null) {
        PropertyName sortingProp = sortBy.getPropertyName();
        String sortType = sortingProp.getPropertyName();
        SortOrder sortOrder =
            (sortBy.getSortOrder() == null) ? SortOrder.DESCENDING : sortBy.getSortOrder();
        logger.debug("Sorting by type: " + sortType);
        logger.debug("Sorting by Order: " + sortBy.getSortOrder());

        // Temporal searches are currently sorted by the effective time
        if (Metacard.EFFECTIVE.equals(sortType) || Result.TEMPORAL.equals(sortType)) {
          coreComparator = new TemporalResultComparator(sortOrder);
        } else if (Result.DISTANCE.equals(sortType)) {
          coreComparator = new DistanceResultComparator(sortOrder);
        } else if (Result.RELEVANCE.equals(sortType)) {
          coreComparator = new RelevanceResultComparator(sortOrder);
        }
      }

      List<Result> resultList = new ArrayList<Result>();
      long totalHits = 0;
      Set<ProcessingDetails> processingDetails = returnResults.getProcessingDetails();

      Map<String, Serializable> returnProperties = returnResults.getProperties();
      for (final Entry<Source, Future<SourceResponse>> entry : futures.entrySet()) {
        Source site = entry.getKey();
        SourceResponse sourceResponse = null;
        try {
          sourceResponse =
              query.getTimeoutMillis() < 1
                  ? entry.getValue().get()
                  : entry.getValue().get(getTimeRemaining(deadline), TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
          logger.warn(
              "Couldn't get results from completed federated query on site with ShortName "
                  + site.getId(),
              e);
          processingDetails.add(new ProcessingDetailsImpl(site.getId(), e));
        } catch (ExecutionException e) {
          logger.warn(
              "Couldn't get results from completed federated query on site " + site.getId(), e);
          if (logger.isDebugEnabled()) {
            logger.debug("Adding exception to response.");
          }
          processingDetails.add(new ProcessingDetailsImpl(site.getId(), e));
        } catch (TimeoutException e) {
          logger.warn("search timed out: " + new Date() + " on site " + site.getId());
          processingDetails.add(new ProcessingDetailsImpl(site.getId(), e));
        }
        if (sourceResponse != null) {
          List<Result> sourceResults = sourceResponse.getResults();
          resultList.addAll(sourceResults);
          long sourceHits = sourceResponse.getHits();

          totalHits += sourceHits;
          Map<String, Serializable> newSourceProperties = new HashMap<String, Serializable>();
          newSourceProperties.put(QueryResponse.TOTAL_HITS, sourceHits);
          newSourceProperties.put(QueryResponse.TOTAL_RESULTS_RETURNED, sourceResults.size());

          Map<String, Serializable> originalSourceProperties = sourceResponse.getProperties();
          if (originalSourceProperties != null) {
            Serializable object = originalSourceProperties.get(QueryResponse.ELAPSED_TIME);
            if (object != null && object instanceof Long) {
              newSourceProperties.put(QueryResponse.ELAPSED_TIME, (Long) object);
              originalSourceProperties.remove(QueryResponse.ELAPSED_TIME);
              logger.debug(
                  "Setting the ellapsedTime responseProperty to {} for source {}",
                  object,
                  site.getId());
            }

            // TODO: for now add all properties into outgoing response's properties.
            // this is not the best idea because we could get properties from records
            // that get eliminated by the max results enforcement done below.
            // See DDF-1183 for a possible solution.
            returnProperties.putAll(originalSourceProperties);
          }
          returnProperties.put(site.getId(), (Serializable) newSourceProperties);
          logger.debug("Setting the query responseProperties for site {}", site.getId());

          // Add a List of siteIds so endpoints know what sites got queried
          Serializable siteListObject = returnProperties.get(QueryResponse.SITE_LIST);
          if (siteListObject != null && siteListObject instanceof List<?>) {
            ((List) siteListObject).add(site.getId());
          } else {
            siteListObject = new ArrayList<String>();
            ((List) siteListObject).add(site.getId());
            returnProperties.put(QueryResponse.SITE_LIST, (Serializable) siteListObject);
          }
        }
      }
      logger.debug("all sites finished returning results: " + resultList.size());

      Collections.sort(resultList, coreComparator);

      returnResults.setHits(totalHits);
      int maxResults = query.getPageSize() > 0 ? query.getPageSize() : Integer.MAX_VALUE;

      returnResults.addResults(
          resultList.size() > maxResults ? resultList.subList(0, maxResults) : resultList, true);
    }