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);
  }
Example #2
0
 /** Existing agents are detected based on email address as well as URI key. */
 @Override
 public Agent getExistingRecord(RequestContext request) throws ResponseContextException {
   // Try super method first
   Agent existingAgent = super.getExistingRecord(request);
   if (existingAgent != null) {
     return existingAgent;
   }
   // If not, it's time for some Agent-specific searching
   Entry entry = getEntryFromRequest(request);
   for (Link link : entry.getLinks(Constants.REL_MBOX)) {
     InternetAddress emailAddress = getAdapterInputHelper().getEmailFromHref(link.getHref());
     existingAgent = getAgentWithEmail(emailAddress);
     if (existingAgent != null) {
       return existingAgent;
     }
   }
   return null;
 }
Example #3
0
 private static IRI getEditUri(Entry entry) throws Exception {
   IRI editUri = null;
   List<Link> editLinks = entry.getLinks("edit");
   for (Link link : editLinks) {
     // if there is more than one edit link, we should not automatically
     // assume that it's always going to point to an Atom document
     // representation.
     if (link.getMimeType() != null) {
       if (link.getMimeType().match("application/atom+xml")) {
         editUri = link.getResolvedHref();
         break;
       }
     } else { // assume that an edit link with no type attribute is the right one to use
       editUri = link.getResolvedHref();
       break;
     }
   }
   return editUri;
 }
  OrganizationsResourceImpl(Link orgsLink) {

    this.orgsLink = orgsLink;

    orgsURI = UriBuilder.fromUri(BASE_URI.toString() + orgsLink.getHref().toString()).build();

    URI uri = UriBuilder.fromUri(BASE_URI.toString() + orgsLink.getHref().toString()).build();
    ClientResponse response =
        ClientUtil.readClientResponse(uri, getHttpClient(), MediaType.APPLICATION_ATOM_XML);

    PaginatedFeedEntitiesList<Organization> pgs;
    if (response.getStatus() == 200) {
      Feed feed = ClientUtil.getFeed(response);

      entries = feed.getEntries();

      orgsLink = feed.getLink(REL_ORG);

      if (response.getHeaders().getFirst("Cache-Control") != null)
        isCacheEnabled = response.getHeaders().getFirst("Cache-Control").equals("no-cache");
      String dateString = response.getHeaders().getFirst("Last-Modified");
      SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
      try {
        lastModifiedDate = format.parse(dateString);
      } catch (Exception ex) {
      }
      dateString = response.getHeaders().getFirst("Expires");
      try {
        lastModifiedDate = format.parse(dateString);
      } catch (Exception ex) {
      }
      uri = response.getLocation();

    } else {

      orgLink = null;
    }
  }
 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);
 }
Example #6
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;
  }
  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;
  }