コード例 #1
0
  /*
   * Gets a List of all categories tuples for a specified name.
   */
  public List<RESTCategoryV1> getCategoriesByName(final String name) {
    final List<RESTCategoryV1> output = new ArrayList<RESTCategoryV1>();

    try {
      BaseRestCollectionV1<RESTCategoryV1, RESTCategoryCollectionV1> categories =
          collectionsCache.get(RESTCategoryV1.class, RESTCategoryCollectionV1.class);
      if (categories.getItems() == null) {
        /* We need to expand the Categories collection */
        final ExpandDataTrunk expand = new ExpandDataTrunk();
        expand.setBranches(
            CollectionUtilities.toArrayList(
                new ExpandDataTrunk(new ExpandDataDetails("categories"))));

        final String expandString = mapper.writeValueAsString(expand);
        // final String expandEncodedString = URLEncoder.encode(expandString, "UTF-8");

        categories = client.getJSONCategories(expandString);
        collectionsCache.add(RESTCategoryV1.class, categories);
      }

      if (categories != null) {
        for (RESTCategoryV1 cat : categories.getItems()) {
          if (cat.getName().equals(name)) {
            output.add(cat);
          }
        }
      }

      return output;
    } catch (Exception e) {
      log.error(ExceptionUtilities.getStackTrace(e));
    }
    return null;
  }