Exemplo n.º 1
0
  /*
   * Gets a List of all type tuples for a specified name.
   */
  public RESTTagV1 getTypeByName(final String name) {
    final List<RESTTagV1> tags = getTagsByName(name);

    // Iterate through the list of tags and check if the tag is a Type and
    // matches the name.
    if (tags != null) {
      for (final RESTTagV1 tag : tags) {
        if (ComponentTagV1.containedInCategory(tag, CSConstants.TYPE_CATEGORY_ID)
            && tag.getName().equals(name)) {
          return tag;
        }
      }
    }
    return null;
  }
Exemplo n.º 2
0
  /*
   * Gets a List of all tag tuples for a specified name.
   */
  public List<RESTTagV1> getTagsByName(final String name) {
    final List<RESTTagV1> output = new ArrayList<RESTTagV1>();

    try {

      BaseRestCollectionV1<RESTTagV1, RESTTagCollectionV1> tags =
          collectionsCache.get(RESTTagV1.class, RESTTagCollectionV1.class);
      if (tags.getItems() == null) {
        /* We need to expand the Tags & Categories collection */
        final ExpandDataTrunk expand = new ExpandDataTrunk();
        final ExpandDataTrunk expandTags = new ExpandDataTrunk(new ExpandDataDetails("tags"));
        expandTags.setBranches(
            CollectionUtilities.toArrayList(
                new ExpandDataTrunk(new ExpandDataDetails("categories"))));
        expand.setBranches(CollectionUtilities.toArrayList(expandTags));

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

        tags = client.getJSONTags(expandString);
        collectionsCache.add(RESTTagV1.class, tags);
      }

      // Iterate through the list of tags and check if the tag is a Type
      // and matches the name.
      if (tags != null) {
        for (final RESTTagV1 tag : tags.getItems()) {
          if (tag.getName().equals(name)) {
            output.add(tag);
          }
        }
      }

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