Пример #1
0
  /**
   * This will obtain assets from Massive using the supplied filters. The map can contain <code>null
   * </code> or empty collections of values, in which case they will not be used in the filter.
   *
   * @param filters A map of attributes to filter on mapped to the values to use
   * @return The filtered assets
   * @throws IOException
   * @throws RequestFailureException
   */
  public Collection<Asset> getFilteredAssets(Map<FilterableAttribute, Collection<String>> filters)
      throws IOException, RequestFailureException {
    // Were any filters defined?
    if (filters == null || allFiltersAreEmpty(filters)) {
      return getAllAssets();
    }

    // Build up a filter string
    Collection<String> filterStrings = new HashSet<String>();
    for (Map.Entry<FilterableAttribute, Collection<String>> filter : filters.entrySet()) {
      Collection<String> values = filter.getValue();
      if (values != null && !values.isEmpty()) {
        filterStrings.add(createListFilter(filter.getKey(), values));
      }
    }

    StringBuilder filterString = new StringBuilder("?");
    boolean isFirst = true;
    for (String filter : filterStrings) {
      if (isFirst) {
        isFirst = false;
      } else {
        filterString.append("&");
      }
      filterString.append(filter);
    }

    // Now do the filtered call into massive
    HttpURLConnection connection =
        createHttpURLConnectionToMassive("/assets" + filterString.toString());
    connection.setRequestMethod("GET");
    testResponseCode(connection);
    return JSONAssetConverter.readValues(connection.getInputStream());
  }
Пример #2
0
  /**
   * Implements the find API for featureManager find
   *
   * <p>NOTE: TODO at the moment this only works when called against an unauthenticated Client due
   * to a problem with how the stores are defined (the company values are defined incorrectly).
   *
   * @param searchString
   * @param typeLabel
   * @param appliesToFilterInfo
   * @return
   * @throws IOException
   * @throws RequestFailureException
   */
  public List<Asset> findAssets(String searchString, TypeLabel assetType, Visibility visible)
      throws IOException, RequestFailureException {

    String encodedSearchString = URLEncoder.encode(searchString, "UTF-8");

    StringBuffer url = new StringBuffer("/assets?q=" + encodedSearchString);
    url.append("&wlpInformation.typeLabel=" + assetType.getValue());

    // visibility is currently not indexed ... when it is this line can be uncommented. Until then
    // it will kill all the results
    // url.append("&wlpInformation.visibility=" + visible.toString());

    // Call massive to run the query
    HttpURLConnection connection = createHttpURLConnectionToMassive(url.toString());
    connection.setRequestMethod("GET");
    testResponseCode(connection);
    InputStream is = connection.getInputStream();

    // take the returned input stream and convert it to assets
    List<Asset> assets = JSONAssetConverter.readValues(is);
    return assets;
  }
Пример #3
0
 /**
  * This method will issue a GET to all of the assets in massive
  *
  * @return A list of all of the assets in Massive
  * @throws IOException
  * @throws RequestFailureException
  */
 public List<Asset> getAllAssets() throws IOException, RequestFailureException {
   HttpURLConnection connection = createHttpURLConnectionToMassive("/assets");
   connection.setRequestMethod("GET");
   testResponseCode(connection);
   return JSONAssetConverter.readValues(connection.getInputStream());
 }