Ejemplo n.º 1
0
  private void addAtomManagedDatastream(Feed feed, String contentLocation) throws Exception {
    String dsId = "DS";

    Entry dsEntry = feed.addEntry();
    dsEntry.setId(feed.getId().toString() + "/" + dsId);

    Entry dsvEntry = feed.addEntry();
    dsvEntry.setId(dsEntry.getId().toString() + "/" + feed.getUpdatedString());

    dsEntry.setTitle(feed.getTitle());
    dsEntry.setUpdated(feed.getUpdated());
    dsEntry.addLink(dsvEntry.getId().toString(), Link.REL_ALTERNATE);
    dsEntry.addCategory(MODEL.STATE.uri, "A", null);
    dsEntry.addCategory(MODEL.CONTROL_GROUP.uri, "M", null);
    dsEntry.addCategory(MODEL.VERSIONABLE.uri, "true", null);

    dsvEntry.setTitle(feed.getTitle());
    dsvEntry.setUpdated(feed.getUpdated());
    ThreadHelper.addInReplyTo(dsvEntry, dsEntry.getId());
    dsvEntry.setSummary("summary");
    dsvEntry.setContent(new IRI(contentLocation), "text/plain");
  }
  private void iterateAndListCollections(ServiceDocument sd, AuthCredentials auth)
      throws Exception {
    if (sd == null) {
      System.out.println("--- Service Document was NULL --");
      return;
    }

    List<SWORDWorkspace> ws = sd.getWorkspaces();
    for (SWORDWorkspace w : ws) {
      List<SWORDCollection> collections = w.getCollections();
      for (SWORDCollection c : collections) {
        System.out.println("Collection: " + c.getTitle());
        IRI href = c.getHref();
        CollectionEntries ces = client.listCollection(href.toString(), auth);
        for (Entry entry : ces.getEntries()) {
          IRI id = entry.getId();
          System.out.println("\t\tID: " + id.toString());
        }
      }
    }
  }
  @Override
  public AdapterResponse<Entry> postEntry(PostEntryRequest postEntryRequest) {
    final Entry abderaParsedEntry = postEntryRequest.getEntry();
    final PersistedEntry persistedEntry = new PersistedEntry();

    // Update our category indicies
    final Set<PersistedCategory> entryCategories =
        feedRepository.updateCategories(processCategories(abderaParsedEntry.getCategories()));
    persistedEntry.setCategories(entryCategories);

    boolean entryIdSent = abderaParsedEntry.getId() != null;

    // Generate an ID for this entry
    if (allowOverrideId
        && entryIdSent
        && StringUtils.isNotBlank(abderaParsedEntry.getId().toString().trim())) {
      String entryId = abderaParsedEntry.getId().toString();
      // Check to see if entry with this id already exists
      PersistedEntry exists = feedRepository.getEntry(entryId, postEntryRequest.getFeedName());
      if (exists != null) {
        String errMsg =
            String.format("Unable to persist entry. Reason: entryId (%s) not unique.", entryId);
        throw new PublicationException(errMsg);
      }
      persistedEntry.setEntryId(abderaParsedEntry.getId().toString());
    } else {
      persistedEntry.setEntryId(UUID_URI_SCHEME + UUID.randomUUID().toString());
      abderaParsedEntry.setId(persistedEntry.getEntryId());
    }

    if (allowOverrideDate) {
      Date updated = abderaParsedEntry.getUpdated();

      if (updated != null) {
        persistedEntry.setDateLastUpdated(updated);
        persistedEntry.setCreationDate(updated);
      }
    }

    if (abderaParsedEntry.getSelfLink() == null) {
      abderaParsedEntry
          .addLink(
              decode(
                      postEntryRequest.urlFor(
                          new EnumKeyedTemplateParameters<URITemplate>(URITemplate.FEED)))
                  + "entries/"
                  + persistedEntry.getEntryId())
          .setRel(LINKREL_SELF);
    }

    final PersistedFeed feedRef =
        new PersistedFeed(
            postEntryRequest.getFeedName(), UUID_URI_SCHEME + UUID.randomUUID().toString());

    persistedEntry.setFeed(feedRef);
    persistedEntry.setEntryBody(entryToString(abderaParsedEntry));

    abderaParsedEntry.setUpdated(persistedEntry.getDateLastUpdated());

    feedRepository.saveEntry(persistedEntry);

    return ResponseBuilder.created(abderaParsedEntry);
  }