Пример #1
0
  /*
   * Gets a list of Revision's from the TopicIndex database for a specific
   * topic
   */
  public List<Object[]> getTopicRevisionsById(final Integer topicId) {
    final List<Object[]> results = new ArrayList<Object[]>();
    try {
      final List<String> additionalKeys =
          CollectionUtilities.toArrayList("revisions", "topic" + topicId);
      final BaseRestCollectionV1<RESTTopicV1, RESTTopicCollectionV1> topicRevisions;
      if (collectionsCache.containsKey(RESTTopicV1.class, additionalKeys)) {
        topicRevisions =
            collectionsCache.get(RESTTopicV1.class, RESTTopicCollectionV1.class, additionalKeys);
      } else {
        /* We need to expand the Revisions collection */
        final ExpandDataTrunk expand = new ExpandDataTrunk();
        final ExpandDataTrunk expandTags = new ExpandDataTrunk(new ExpandDataDetails("tags"));
        final ExpandDataTrunk expandRevs = new ExpandDataTrunk(new ExpandDataDetails("revisions"));
        expandTags.setBranches(
            CollectionUtilities.toArrayList(
                new ExpandDataTrunk(new ExpandDataDetails("categories"))));
        expandRevs.setBranches(
            CollectionUtilities.toArrayList(
                expandTags,
                new ExpandDataTrunk(new ExpandDataDetails("sourceUrls")),
                new ExpandDataTrunk(new ExpandDataDetails("properties")),
                new ExpandDataTrunk(new ExpandDataDetails("outgoingRelationships")),
                new ExpandDataTrunk(new ExpandDataDetails("incomingRelationships"))));
        expand.setBranches(CollectionUtilities.toArrayList(expandRevs));

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

        final RESTTopicV1 topic = client.getJSONTopic(topicId, expandString);
        collectionsCache.add(RESTTopicV1.class, topic.getRevisions(), additionalKeys, true);
        topicRevisions = topic.getRevisions();
      }

      // Create the custom revisions list
      if (topicRevisions != null && topicRevisions.getItems() != null) {
        for (final RESTTopicV1 topicRev : topicRevisions.getItems()) {
          Object[] revision = new Object[2];
          revision[0] = topicRev.getRevision();
          revision[1] = topicRev.getLastModified();
          results.add(revision);
        }
      }
      return results;
    } catch (Exception e) {
      log.debug(e.getMessage());
      e.printStackTrace();
    }
    return null;
  }
Пример #2
0
 /*
  * Gets a specific category tuple from the database as specified by the
  * categories ID.
  */
 public RESTCategoryV1 getCategoryById(final int id) {
   try {
     if (entityCache.containsKeyValue(RESTCategoryV1.class, id)) {
       return entityCache.get(RESTCategoryV1.class, id);
     } else {
       final RESTCategoryV1 category = client.getJSONCategory(id, null);
       entityCache.add(category);
       return category;
     }
   } catch (Exception e) {
     log.debug(e.getMessage());
     e.printStackTrace();
   }
   return null;
 }