コード例 #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;
  }
コード例 #2
0
  /*
   * Gets a List of all User tuples for a specified name.
   */
  public List<RESTUserV1> getUsersByName(final String userName) {
    final List<RESTUserV1> output = new ArrayList<RESTUserV1>();

    try {
      final BaseRestCollectionV1<RESTUserV1, RESTUserCollectionV1> users;
      if (collectionsCache.containsKey(RESTUserV1.class)) {
        users = collectionsCache.get(RESTUserV1.class, RESTUserCollectionV1.class);
      } else {
        /* We need to expand the Users collection */
        final ExpandDataTrunk expand = new ExpandDataTrunk();
        expand.setBranches(
            CollectionUtilities.toArrayList(new ExpandDataTrunk(new ExpandDataDetails("users"))));

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

        users = client.getJSONUsers(expandString);
        collectionsCache.add(RESTUserV1.class, users);
      }

      if (users != null) {
        for (RESTUserV1 user : users.getItems()) {
          if (user.getName().equals(userName)) {
            output.add(user);
          }
        }
      }

      return output;
    } catch (Exception e) {
      log.error(ExceptionUtilities.getStackTrace(e));
    }
    return null;
  }
コード例 #3
0
  /*
   * Gets a list of Revision's from the CSProcessor database for a specific
   * content spec
   */
  public List<Object[]> getContentSpecRevisionsById(final Integer csId) {
    final List<Object[]> results = new ArrayList<Object[]>();
    try {
      final List<String> additionalKeys =
          CollectionUtilities.toArrayList("revision", "topic" + csId);
      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(expandTags, expandRevs));

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

        final RESTTopicV1 topic = client.getJSONTopic(csId, expandString);
        // Check that the topic is a content spec
        if (!ComponentBaseTopicV1.hasTag(topic, CSConstants.CONTENT_SPEC_TAG_ID)) return null;

        // Add the content spec revisions to the cache
        collectionsCache.add(RESTTopicV1.class, topic.getRevisions(), additionalKeys, true);
        topicRevisions = topic.getRevisions();
      }

      // Create the unique array from the revisions
      if (topicRevisions != null && topicRevisions.getItems() != null) {
        for (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.error(ExceptionUtilities.getStackTrace(e));
    }
    return null;
  }
コード例 #4
0
  /*
   * Gets a list of all content specifications in the database or the first 50
   * if limit is set
   */
  public List<RESTTopicV1> getContentSpecs(Integer startPos, Integer limit) {
    final List<RESTTopicV1> results = new ArrayList<RESTTopicV1>();

    try {
      final BaseRestCollectionV1<RESTTopicV1, RESTTopicCollectionV1> topics;

      // Set the startPos and limit to zero if they are null
      startPos = startPos == null ? 0 : startPos;
      limit = limit == null ? 0 : limit;

      final List<String> additionalKeys =
          CollectionUtilities.toArrayList("start-" + startPos, "end-" + (startPos + limit));
      if (collectionsCache.containsKey(RESTTopicV1.class, additionalKeys)) {
        topics =
            collectionsCache.get(RESTTopicV1.class, RESTTopicCollectionV1.class, additionalKeys);
      } else {
        /* We need to expand the topics collection */
        final ExpandDataTrunk expand = new ExpandDataTrunk();
        ExpandDataDetails expandDataDetails = new ExpandDataDetails("topics");
        if (startPos != 0 && startPos != null) {
          expandDataDetails.setStart(startPos);
        }
        if (limit != 0 && limit != null) {
          expandDataDetails.setEnd(startPos + limit);
        }

        final ExpandDataTrunk expandTopics = new ExpandDataTrunk(expandDataDetails);
        final ExpandDataTrunk expandTags = new ExpandDataTrunk(new ExpandDataDetails("tags"));
        expandTags.setBranches(
            CollectionUtilities.toArrayList(
                new ExpandDataTrunk(new ExpandDataDetails("categories"))));
        expandTopics.setBranches(
            CollectionUtilities.toArrayList(
                expandTags, new ExpandDataTrunk(new ExpandDataDetails("properties"))));

        expand.setBranches(CollectionUtilities.toArrayList(expandTopics));

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

        PathSegment path =
            new PathSegmentImpl("query;tag" + CSConstants.CONTENT_SPEC_TAG_ID + "=1;", false);
        topics = client.getJSONTopicsWithQuery(path, expandString);
        collectionsCache.add(RESTTopicV1.class, topics, additionalKeys);
      }

      return topics.getItems();
    } catch (Exception e) {
      log.error(ExceptionUtilities.getStackTrace(e));
    }
    return results;
  }
コード例 #5
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;
  }
コード例 #6
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;
  }