Beispiel #1
0
  /**
   * Add options to the search scope field. This field determines in what communities or collections
   * to search for the query.
   *
   * <p>The scope list will depend upon the current search scope. There are three cases:
   *
   * <p>No current scope: All top level communities are listed.
   *
   * <p>The current scope is a community: All collections contained within the community are listed.
   *
   * <p>The current scope is a collection: All parent communities are listed.
   *
   * @param scope The current scope field.
   */
  protected void buildScopeList(Select scope) throws SQLException, WingException {

    DSpaceObject scopeDSO = getScope();
    if (scopeDSO == null) {
      // No scope, display all root level communities
      scope.addOption("/", T_all_of_dspace);
      scope.setOptionSelected("/");
      for (Community community : Community.findAllTop(context)) {
        scope.addOption(community.getHandle(), community.getMetadata("name"));
      }
    } else if (scopeDSO instanceof Community) {
      // The scope is a community, display all collections contained
      // within
      Community community = (Community) scopeDSO;
      scope.addOption("/", T_all_of_dspace);
      scope.addOption(community.getHandle(), community.getMetadata("name"));
      scope.setOptionSelected(community.getHandle());

      for (Collection collection : community.getCollections()) {
        scope.addOption(collection.getHandle(), collection.getMetadata("name"));
      }
    } else if (scopeDSO instanceof Collection) {
      // The scope is a collection, display all parent collections.
      Collection collection = (Collection) scopeDSO;
      scope.addOption("/", T_all_of_dspace);
      scope.addOption(collection.getHandle(), collection.getMetadata("name"));
      scope.setOptionSelected(collection.getHandle());

      Community[] communities = collection.getCommunities()[0].getAllParents();
      for (Community community : communities) {
        scope.addOption(community.getHandle(), community.getMetadata("name"));
      }
    }
  }
 /**
  * processCurateCommunity
  *
  * <p>Utility method to process curation tasks submitted via the DSpace GUI
  *
  * @param context
  * @param dsoID
  * @param request
  */
 public static FlowResult processCurateCommunity(Context context, int dsoID, Request request)
     throws AuthorizeException, IOException, SQLException, Exception {
   String task = request.getParameter("curate_task");
   Curator curator = FlowCurationUtils.getCurator(task);
   try {
     Community community = Community.find(context, dsoID);
     if (community != null) {
       // Call curate(context,ID) to ensure a Task Performer (Eperson) is set in Curator
       curator.curate(context, community.getHandle());
     }
     return FlowCurationUtils.getRunFlowResult(task, curator, true);
   } catch (Exception e) {
     curator.setResult(task, e.getMessage());
     return FlowCurationUtils.getRunFlowResult(task, curator, false);
   }
 }
 /** queues curation tasks */
 public static FlowResult processQueueCommunity(Context context, int dsoID, Request request)
     throws AuthorizeException, IOException, SQLException, Exception {
   String task = request.getParameter("curate_task");
   Curator curator = FlowCurationUtils.getCurator(task);
   String objId = String.valueOf(dsoID);
   String taskQueueName = ConfigurationManager.getProperty("curate", "ui.queuename");
   boolean status = false;
   Community community = Community.find(context, dsoID);
   if (community != null) {
     objId = community.getHandle();
     try {
       curator.queue(context, objId, taskQueueName);
       status = true;
     } catch (IOException ioe) {
       // no-op
     }
   }
   return FlowCurationUtils.getQueueFlowResult(task, status, objId, taskQueueName);
 }
Beispiel #4
0
  /**
   * Take a node list of communities and build the structure from them, delegating to the relevant
   * methods in this class for sub-communities and collections
   *
   * @param context the context of the request
   * @param communities a nodelist of communities to create along with their sub-structures
   * @param parent the parent community of the nodelist of communities to create
   * @return an element array containing additional information regarding the created communities
   *     (e.g. the handles they have been assigned)
   */
  private static Element[] handleCommunities(
      Context context, NodeList communities, Community parent) throws Exception {
    Element[] elements = new Element[communities.getLength()];

    for (int i = 0; i < communities.getLength(); i++) {
      Community community;
      Element element = new Element("community");

      // create the community or sub community
      if (parent != null) {
        community = parent.createSubcommunity();
      } else {
        community = Community.create(null, context);
      }

      // default the short description to be an empty string
      community.setMetadata("short_description", " ");

      // now update the metadata
      Node tn = communities.item(i);
      for (Map.Entry<String, String> entry : communityMap.entrySet()) {
        NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
        if (nl.getLength() == 1) {
          community.setMetadata(entry.getValue(), getStringValue(nl.item(0)));
        }
      }

      // FIXME: at the moment, if the community already exists by name
      // then this will throw a PSQLException on a duplicate key
      // violation
      // Ideally we'd skip this row and continue to create sub
      // communities
      // and so forth where they don't exist, but it's proving
      // difficult
      // to isolate the community that already exists without hitting
      // the database directly.
      community.update();

      // build the element with the handle that identifies the new
      // community
      // along with all the information that we imported here
      // This looks like a lot of repetition of getting information
      // from above
      // but it's here to keep it separate from the create process in
      // case
      // we want to move it or make it switchable later
      element.setAttribute("identifier", community.getHandle());

      Element nameElement = new Element("name");
      nameElement.setText(community.getMetadata("name"));
      element.addContent(nameElement);

      if (community.getMetadata("short_description") != null) {
        Element descriptionElement = new Element("description");
        descriptionElement.setText(community.getMetadata("short_description"));
        element.addContent(descriptionElement);
      }

      if (community.getMetadata("introductory_text") != null) {
        Element introElement = new Element("intro");
        introElement.setText(community.getMetadata("introductory_text"));
        element.addContent(introElement);
      }

      if (community.getMetadata("copyright_text") != null) {
        Element copyrightElement = new Element("copyright");
        copyrightElement.setText(community.getMetadata("copyright_text"));
        element.addContent(copyrightElement);
      }

      if (community.getMetadata("side_bar_text") != null) {
        Element sidebarElement = new Element("sidebar");
        sidebarElement.setText(community.getMetadata("side_bar_text"));
        element.addContent(sidebarElement);
      }

      // handle sub communities
      NodeList subCommunities = XPathAPI.selectNodeList(tn, "community");
      Element[] subCommunityElements = handleCommunities(context, subCommunities, community);

      // handle collections
      NodeList collections = XPathAPI.selectNodeList(tn, "collection");
      Element[] collectionElements = handleCollections(context, collections, community);

      int j;
      for (j = 0; j < subCommunityElements.length; j++) {
        element.addContent(subCommunityElements[j]);
      }
      for (j = 0; j < collectionElements.length; j++) {
        element.addContent(collectionElements[j]);
      }

      elements[i] = element;
    }

    return elements;
  }
Beispiel #5
0
  /**
   * Fills in the feed and entry-level metadata from DSpace objects.
   *
   * @param request request
   * @param context context
   * @param dso DSpaceObject
   * @param items array of objects
   * @param labels label map
   */
  public void populate(
      HttpServletRequest request,
      Context context,
      DSpaceObject dso,
      List<? extends DSpaceObject> items,
      Map<String, String> labels) {
    String logoURL = null;
    String objectURL = null;
    String defaultTitle = null;
    boolean podcastFeed = false;
    this.request = request;

    // dso is null for the whole site, or a search without scope
    if (dso == null) {
      defaultTitle = ConfigurationManager.getProperty("dspace.name");
      feed.setDescription(localize(labels, MSG_FEED_DESCRIPTION));
      objectURL = resolveURL(request, null);
      logoURL = ConfigurationManager.getProperty("webui.feed.logo.url");
    } else {
      Bitstream logo = null;
      if (dso.getType() == Constants.COLLECTION) {
        Collection col = (Collection) dso;
        defaultTitle = col.getName();
        feed.setDescription(collectionService.getMetadata(col, "short_description"));
        logo = col.getLogo();
        String cols = ConfigurationManager.getProperty("webui.feed.podcast.collections");
        if (cols != null && cols.length() > 1 && cols.contains(col.getHandle())) {
          podcastFeed = true;
        }
      } else if (dso.getType() == Constants.COMMUNITY) {
        Community comm = (Community) dso;
        defaultTitle = comm.getName();
        feed.setDescription(communityService.getMetadata(comm, "short_description"));
        logo = comm.getLogo();
        String comms = ConfigurationManager.getProperty("webui.feed.podcast.communities");
        if (comms != null && comms.length() > 1 && comms.contains(comm.getHandle())) {
          podcastFeed = true;
        }
      }
      objectURL = resolveURL(request, dso);
      if (logo != null) {
        logoURL = urlOfBitstream(request, logo);
      }
    }
    feed.setTitle(
        labels.containsKey(MSG_FEED_TITLE) ? localize(labels, MSG_FEED_TITLE) : defaultTitle);
    feed.setLink(objectURL);
    feed.setPublishedDate(new Date());
    feed.setUri(objectURL);

    // add logo if we found one:
    if (logoURL != null) {
      // we use the path to the logo for this, the logo itself cannot
      // be contained in the rdf. Not all RSS-viewers show this logo.
      SyndImage image = new SyndImageImpl();
      image.setLink(objectURL);
      if (StringUtils.isNotBlank(feed.getTitle())) {
        image.setTitle(feed.getTitle());
      } else {
        image.setTitle(localize(labels, MSG_LOGO_TITLE));
      }
      image.setUrl(logoURL);
      feed.setImage(image);
    }

    // add entries for items
    if (items != null) {
      List<SyndEntry> entries = new ArrayList<SyndEntry>();
      for (DSpaceObject itemDSO : items) {
        if (itemDSO.getType() != Constants.ITEM) {
          continue;
        }
        Item item = (Item) itemDSO;
        boolean hasDate = false;
        SyndEntry entry = new SyndEntryImpl();
        entries.add(entry);

        String entryURL = resolveURL(request, item);
        entry.setLink(entryURL);
        entry.setUri(entryURL);

        String title = getOneDC(item, titleField);
        entry.setTitle(title == null ? localize(labels, MSG_UNTITLED) : title);

        // "published" date -- should be dc.date.issued
        String pubDate = getOneDC(item, dateField);
        if (pubDate != null) {
          entry.setPublishedDate((new DCDate(pubDate)).toDate());
          hasDate = true;
        }
        // date of last change to Item
        entry.setUpdatedDate(item.getLastModified());

        StringBuffer db = new StringBuffer();
        for (String df : descriptionFields) {
          // Special Case: "(date)" in field name means render as date
          boolean isDate = df.indexOf("(date)") > 0;
          if (isDate) {
            df = df.replaceAll("\\(date\\)", "");
          }

          List<MetadataValue> dcv = itemService.getMetadataByMetadataString(item, df);
          if (dcv.size() > 0) {
            String fieldLabel = labels.get(MSG_METADATA + df);
            if (fieldLabel != null && fieldLabel.length() > 0) {
              db.append(fieldLabel).append(": ");
            }
            boolean first = true;
            for (MetadataValue v : dcv) {
              if (first) {
                first = false;
              } else {
                db.append("; ");
              }
              db.append(isDate ? new DCDate(v.getValue()).toString() : v.getValue());
            }
            db.append("\n");
          }
        }
        if (db.length() > 0) {
          SyndContent desc = new SyndContentImpl();
          desc.setType("text/plain");
          desc.setValue(db.toString());
          entry.setDescription(desc);
        }

        // This gets the authors into an ATOM feed
        List<MetadataValue> authors = itemService.getMetadataByMetadataString(item, authorField);
        if (authors.size() > 0) {
          List<SyndPerson> creators = new ArrayList<SyndPerson>();
          for (MetadataValue author : authors) {
            SyndPerson sp = new SyndPersonImpl();
            sp.setName(author.getValue());
            creators.add(sp);
          }
          entry.setAuthors(creators);
        }

        // only add DC module if any DC fields are configured
        if (dcCreatorField != null || dcDateField != null || dcDescriptionField != null) {
          DCModule dc = new DCModuleImpl();
          if (dcCreatorField != null) {
            List<MetadataValue> dcAuthors =
                itemService.getMetadataByMetadataString(item, dcCreatorField);
            if (dcAuthors.size() > 0) {
              List<String> creators = new ArrayList<String>();
              for (MetadataValue author : dcAuthors) {
                creators.add(author.getValue());
              }
              dc.setCreators(creators);
            }
          }
          if (dcDateField != null && !hasDate) {
            List<MetadataValue> v = itemService.getMetadataByMetadataString(item, dcDateField);
            if (v.size() > 0) {
              dc.setDate((new DCDate(v.get(0).getValue())).toDate());
            }
          }
          if (dcDescriptionField != null) {
            List<MetadataValue> v =
                itemService.getMetadataByMetadataString(item, dcDescriptionField);
            if (v.size() > 0) {
              StringBuffer descs = new StringBuffer();
              for (MetadataValue d : v) {
                if (descs.length() > 0) {
                  descs.append("\n\n");
                }
                descs.append(d.getValue());
              }
              dc.setDescription(descs.toString());
            }
          }
          entry.getModules().add(dc);
        }

        // iTunes Podcast Support - START
        if (podcastFeed) {
          // Add enclosure(s)
          List<SyndEnclosure> enclosures = new ArrayList();
          try {
            List<Bundle> bunds = itemService.getBundles(item, "ORIGINAL");
            if (bunds.get(0) != null) {
              List<Bitstream> bits = bunds.get(0).getBitstreams();
              for (Bitstream bit : bits) {
                String mime = bit.getFormat(context).getMIMEType();
                if (ArrayUtils.contains(podcastableMIMETypes, mime)) {
                  SyndEnclosure enc = new SyndEnclosureImpl();
                  enc.setType(bit.getFormat(context).getMIMEType());
                  enc.setLength(bit.getSize());
                  enc.setUrl(urlOfBitstream(request, bit));
                  enclosures.add(enc);
                } else {
                  continue;
                }
              }
            }
            // Also try to add an external value from dc.identifier.other
            // We are assuming that if this is set, then it is a media file
            List<MetadataValue> externalMedia =
                itemService.getMetadataByMetadataString(item, externalSourceField);
            if (externalMedia.size() > 0) {
              for (MetadataValue anExternalMedia : externalMedia) {
                SyndEnclosure enc = new SyndEnclosureImpl();
                enc.setType(
                    "audio/x-mpeg"); // We can't determine MIME of external file, so just picking
                                     // one.
                enc.setLength(1);
                enc.setUrl(anExternalMedia.getValue());
                enclosures.add(enc);
              }
            }

          } catch (Exception e) {
            System.out.println(e.getMessage());
          }
          entry.setEnclosures(enclosures);

          // Get iTunes specific fields: author, subtitle, summary, duration, keywords
          EntryInformation itunes = new EntryInformationImpl();

          String author = getOneDC(item, authorField);
          if (author != null && author.length() > 0) {
            itunes.setAuthor(author); // <itunes:author>
          }

          itunes.setSubtitle(
              title == null ? localize(labels, MSG_UNTITLED) : title); // <itunes:subtitle>

          if (db.length() > 0) {
            itunes.setSummary(db.toString()); // <itunes:summary>
          }

          String extent =
              getOneDC(
                  item,
                  "dc.format.extent"); // assumed that user will enter this field with length of
                                       // song in seconds
          if (extent != null && extent.length() > 0) {
            extent = extent.split(" ")[0];
            Integer duration = Integer.parseInt(extent);
            itunes.setDuration(new Duration(duration)); // <itunes:duration>
          }

          String subject = getOneDC(item, "dc.subject");
          if (subject != null && subject.length() > 0) {
            String[] subjects = new String[1];
            subjects[0] = subject;
            itunes.setKeywords(subjects); // <itunes:keywords>
          }

          entry.getModules().add(itunes);
        }
      }
      feed.setEntries(entries);
    }
  }