Пример #1
0
  private void populateEntry(Context context, Entry entry, Bitstream bitstream)
      throws DSpaceSwordException {
    BitstreamFormat format = bitstream.getFormat();
    String contentType = null;
    if (format != null) {
      contentType = format.getMIMEType();
    }

    SwordUrlManager urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context);
    String bsUrl = urlManager.getBitstreamUrl(bitstream);

    entry.setId(bsUrl);
    entry.setTitle(bitstream.getName());
    String desc = bitstream.getDescription();
    if ("".equals(desc) || desc == null) {
      desc = bitstream.getName();
    }
    entry.setSummary(desc);
    entry.setUpdated(new Date()); // required, though content is spurious

    // add an edit-media link for the bitstream ...
    Abdera abdera = new Abdera();
    Link link = abdera.getFactory().newLink();
    link.setHref(urlManager.getActionableBitstreamUrl(bitstream));
    link.setMimeType(contentType);
    link.setRel("edit-media");
    entry.addLink(link);

    // set the content of the bitstream
    entry.setContent(new IRI(bsUrl), contentType);
  }
  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");
  }
Пример #3
0
 private void setLinkForTask(Task t, String ticket, RequestContext context, Entry e, String user)
     throws Exception {
   Factory factory = context.getAbdera().getFactory();
   Link link = factory.newLink();
   String formLink = URIUtils.getFormURLForTask(_manager, t, ticket, user);
   // if the URL of the form manager are relative URLs, we want to have a proper link back to the
   // machine.
   // localhost won't work for most RSS readers, so using loopback ip address in this very specific
   // case
   if (!formLink.toLowerCase().startsWith("http")) { // relative URL
     IRI baseUri = context.getBaseUri();
     String host = baseUri.getHost();
     host = host.equals("localhost") ? "127.0.0.1" : host;
     String base = baseUri.getScheme() + "//" + host + ":" + baseUri.getPort();
     link.setBaseUri(base);
   } else {
     link.setBaseUri(StringUtils.EMPTY);
   }
   link.setHref(formLink);
   link.setTitle("Link to " + t.getDescription());
   link.setText("Link to " + t.getDescription());
   e.addLink(link);
 }
Пример #4
0
  public static Entry toPackageEntryAbdera(ModuleItem p, UriInfo uriInfo) {
    URI baseURL;
    if (p.isHistoricalVersion()) {
      baseURL =
          uriInfo
              .getBaseUriBuilder()
              .path("packages/{packageName}/versions/{version}")
              .build(p.getName(), Long.toString(p.getVersionNumber()));
    } else {
      baseURL = uriInfo.getBaseUriBuilder().path("packages/{packageName}").build(p.getName());
    }

    Factory factory = Abdera.getNewFactory();

    org.apache.abdera.model.Entry e = factory.getAbdera().newEntry();
    e.setTitle(p.getTitle());
    e.setSummary(p.getDescription());
    e.setPublished(new Date(p.getLastModified().getTimeInMillis()));
    e.setBaseUri(baseURL.toString());
    e.addAuthor(p.getLastContributor());

    e.setId(baseURL.toString());

    Iterator<AssetItem> i = p.getAssets();
    while (i.hasNext()) {
      AssetItem item = i.next();
      org.apache.abdera.model.Link l = factory.newLink();

      l.setHref(
          UriBuilder.fromUri(baseURL).path("assets/{assetName}").build(item.getName()).toString());
      l.setTitle(item.getTitle());
      l.setRel("asset");
      e.addLink(l);
    }

    // generate meta data
    ExtensibleElement extension = e.addExtension(METADATA);
    ExtensibleElement childExtension = extension.addExtension(ARCHIVED);
    // childExtension.setAttributeValue("type", ArtifactsRepository.METADATA_TYPE_STRING);
    childExtension.addSimpleExtension(VALUE, p.isArchived() ? "true" : "false");

    childExtension = extension.addExtension(UUID);
    childExtension.addSimpleExtension(VALUE, p.getUUID());

    childExtension = extension.addExtension(STATE);
    childExtension.addSimpleExtension(VALUE, p.getState() == null ? "" : p.getState().getName());

    childExtension = extension.addExtension(VERSION_NUMBER);
    childExtension.addSimpleExtension(VALUE, String.valueOf(p.getVersionNumber()));

    childExtension = extension.addExtension(CHECKIN_COMMENT);
    childExtension.addSimpleExtension(VALUE, p.getCheckinComment());

    org.apache.abdera.model.Content content = factory.newContent();
    content.setSrc(UriBuilder.fromUri(baseURL).path("binary").build().toString());
    content.setMimeType("application/octet-stream");
    content.setContentType(Type.MEDIA);
    e.setContentElement(content);

    return e;
  }
Пример #5
0
  public static void main(String[] args) throws Exception {

    Abdera abdera = new Abdera();
    AbderaClient abderaClient = new AbderaClient(abdera);
    Factory factory = abdera.getFactory();

    // Perform introspection. This is an optional step. If you already
    // know the URI of the APP collection to POST to, you can skip it.
    Document<Service> introspection =
        abderaClient.get("http://localhost:9080/EmployeeService/").getDocument();
    Service service = introspection.getRoot();
    Collection collection =
        service.getCollection("Employee Directory Workspace", "itc Employee Database");
    report("The Collection Element", collection.toString());

    // Create the entry to post to the collection
    Entry entry = factory.newEntry();
    entry.setId("tag:example.org,2006:foo");
    entry.setTitle("This is the title");
    entry.setUpdated(new AtomDate().getValue());
    entry.setPublished(new AtomDate().getValue());
    entry.addLink("/employee");
    entry.addAuthor("James");
    entry.setContent("This is the content");
    report("The Entry to Post", entry.toString());

    // Post the entry. Be sure to grab the resolved HREF of the collection
    Document<Entry> doc =
        abderaClient.post(collection.getResolvedHref().toString(), entry).getDocument();

    // In some implementations (such as Google's GData API, the entry URI is
    // distinct from it's edit URI. To be safe, we should assume it may be
    // different
    IRI entryUri = doc.getBaseUri();
    report("The Created Entry", doc.getRoot().toString());

    // Grab the Edit URI from the entry. The entry MAY have more than one
    // edit link. We need to make sure we grab the right one.
    IRI editUri = getEditUri(doc.getRoot());

    // If there is an Edit Link, we can edit the entry
    if (editUri != null) {
      // Before we can edit, we need to grab an "editable" representation
      doc = abderaClient.get(editUri.toString()).getDocument();

      // Change whatever you want in the retrieved entry
      // doc.getRoot().getTitleElement().setValue("This is the changed title");

      // Put it back to the server
      abderaClient.put(editUri.toString(), doc.getRoot());

      // This is just to show that the entry has been modified
      doc = abderaClient.get(entryUri.toString()).getDocument();
      report("The Modified Entry", doc.getRoot().toString());
    } else {
      // Otherwise, the entry cannot be modified (no suitable edit link was found)
      report("The Entry cannot be modified", null);
    }

    // Delete the entry. Again, we need to make sure that we have the current
    // edit link for the entry
    doc = abderaClient.get(entryUri.toString()).getDocument();
    editUri = getEditUri(doc.getRoot());
    if (editUri != null) {
      abderaClient.delete(editUri.toString());
      report("The Enry has been deleted", null);
    } else {
      report("The Entry cannot be deleted", null);
    }
  }
  @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);
  }