private Feed getUserFeed() throws UriBuilderException, IllegalArgumentException {
    Feed userFeed = getFeed(userName, new Date());
    userFeed.setTitle(userName);

    // add a self link
    userFeed.addLink(getSelfLink());

    // add a edit link
    Link editLink = getAbderaFactory().newLink();
    editLink.setHref(getUriInfo().getRequestUri().toString());
    editLink.setRel(Link.REL_EDIT);
    editLink.setMimeType(MediaType.APPLICATION_JSON);
    userFeed.addLink(editLink);

    // add a alternate link
    Link altLink = getAbderaFactory().newLink();
    altLink.setHref(
        getRelativeURIBuilder()
            .path(OrganizationUserResource.class)
            .path(USER_CONTENT_METHOD)
            .build(organizationUniqueShortName, userName)
            .toString());
    altLink.setRel(Link.REL_ALTERNATE);
    altLink.setMimeType(MediaType.APPLICATION_JSON);
    userFeed.addLink(altLink);

    Link privilegesLink = getAbderaFactory().newLink();
    privilegesLink.setHref(
        getRelativeURIBuilder()
            .path(UserPrivilegesResource.class)
            .build(organizationUniqueShortName, userName)
            .toString());
    privilegesLink.setRel(REL_USER_PRIVILEGES);
    privilegesLink.setMimeType(MediaType.APPLICATION_JSON);
    userFeed.addLink(privilegesLink);

    Link rolesLink = getAbderaFactory().newLink();
    rolesLink.setHref(
        getRelativeURIBuilder()
            .path(UserRolesResource.class)
            .build(organizationUniqueShortName, userName)
            .toString());
    rolesLink.setRel(REL_USER_ROLES);
    rolesLink.setMimeType(MediaType.APPLICATION_JSON);
    userFeed.addLink(rolesLink);

    Link organizationLink = getAbderaFactory().newLink();
    organizationLink.setHref(
        getRelativeURIBuilder()
            .path(OrganizationResource.class)
            .build(organizationUniqueShortName)
            .toString());
    organizationLink.setRel("organization");
    organizationLink.setMimeType(MediaType.APPLICATION_JSON);
    userFeed.addLink(organizationLink);

    return userFeed;
  }
Пример #2
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);
  }
Пример #3
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;
  }