예제 #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"));
      }
    }
  }
예제 #2
0
 public CollectionEntity(
     final Collection collection,
     final List<Entity> items,
     final List<Entity> communities,
     final int itemsCount)
     throws SQLException {
   super(
       collection.getID(),
       collection.getName(),
       collection.getType(),
       items,
       communities,
       itemsCount);
   this.canEdit = collection.canEditBoolean();
   this.handle = collection.getHandle();
   this.licence = collection.getLicense();
   this.short_description = collection.getMetadata("short_description");
   this.intro_text = collection.getMetadata("introductory_text");
   this.copyright_text = collection.getMetadata("copyright_text");
   this.sidebar_text = collection.getMetadata("side_bar_text");
   this.provenance = collection.getMetadata("provenance_description");
   if (collection.getLogo() == null) {
     this.logo = null;
   } else {
     this.logo = new BitstreamEntityId(collection.getLogo());
   }
 }
  /** Add a page title and trail links. */
  public void addPageMeta(PageMeta pageMeta)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (!(dso instanceof Collection)) return;

    Collection collection = (Collection) dso;

    // Set the page title
    pageMeta.addMetadata("title").addContent(collection.getMetadata("name"));

    pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
    HandleUtil.buildHandleTrail(collection, pageMeta, contextPath);

    // Add RSS links if available
    String formats = ConfigurationManager.getProperty("webui.feed.formats");
    if (formats != null) {
      for (String format : formats.split(",")) {
        // Remove the protocol number, i.e. just list 'rss' or' atom'
        String[] parts = format.split("_");
        if (parts.length < 1) continue;

        String feedFormat = parts[0].trim() + "+xml";

        String feedURL = contextPath + "/feed/" + collection.getHandle() + "/" + format.trim();
        pageMeta.addMetadata("feed", feedFormat).addContent(feedURL);
      }
    }
  }
  private void populateTableRowFromCollection(Collection collection, TableRow row) {
    int id = collection.getID();
    Bitstream logo = collection.getLogo();
    Item templateItem = collection.getTemplateItem();
    Group admins = collection.getAdministrators();
    Group[] workflowGroups = collection.getWorkflowGroups();

    if (logo == null) {
      row.setColumnNull("logo_bitstream_id");
    } else {
      row.setColumn("logo_bitstream_id", logo.getID());
    }

    if (templateItem == null) {
      row.setColumnNull("template_item_id");
    } else {
      row.setColumn("template_item_id", templateItem.getID());
    }

    if (admins == null) {
      row.setColumnNull("admin");
    } else {
      row.setColumn("admin", admins.getID());
    }

    for (int i = 1; i <= workflowGroups.length; i++) {
      Group g = workflowGroups[i - 1];
      if (g == null) {
        row.setColumnNull("workflow_step_" + i);
      } else {
        row.setColumn("workflow_step_" + i, g.getID());
      }
    }

    // Now loop over all allowed metadata fields and set the value into the
    // TableRow.
    for (CollectionMetadataField field : CollectionMetadataField.values()) {
      String value = collection.getMetadata(field.toString());
      if (value == null) {
        row.setColumnNull(field.toString());
      } else {
        row.setColumn(field.toString(), value);
      }
    }

    row.setColumn("uuid", collection.getIdentifier().getUUID().toString());
  }
  private static void notifyOfReject(Context c, WorkflowItem wi, EPerson e, String reason) {
    try {
      // Get the item title
      String title = getItemTitle(wi);

      // Get the collection
      Collection coll = wi.getCollection();

      // Get rejector's name
      String rejector = getEPersonName(e);
      Locale supportedLocale = I18nUtil.getEPersonLocale(e);
      Email email =
          ConfigurationManager.getEmail(
              I18nUtil.getEmailFilename(supportedLocale, "submit_reject"));

      email.addRecipient(getSubmitterEPerson(wi).getEmail());
      email.addArgument(title);
      email.addArgument(coll.getMetadata("name"));
      email.addArgument(rejector);
      email.addArgument(reason);
      email.addArgument(getMyDSpaceLink());

      email.send();
    } catch (Exception ex) {
      // log this email error
      log.warn(
          LogManager.getHeader(
              c,
              "notify_of_reject",
              "cannot email user"
                  + " eperson_id"
                  + e.getID()
                  + " eperson_email"
                  + e.getEmail()
                  + " workflow_item_id"
                  + wi.getID()));
    }
  }
  /** notify the submitter that the item is archived */
  private static void notifyOfArchive(Context c, Item i, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = i.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email =
          ConfigurationManager.getEmail(
              I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = HandleManager.findHandle(c, i);

      // Get title
      DCValue[] titles = i.getDC("title", null, Item.ANY);
      String title = "";
      try {
        title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
      } catch (MissingResourceException e) {
        title = "Untitled";
      }
      if (titles.length > 0) {
        title = titles[0].value;
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getMetadata("name"));
      email.addArgument(HandleManager.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              c, "notifyOfArchive", "cannot email user" + " item_id=" + i.getID()));
    }
  }
  private static void notifyGroupOfTask(Context c, WorkflowItem wi, Group mygroup, EPerson[] epa)
      throws SQLException, IOException {
    // check to see if notification is turned off
    // and only do it once - delete key after notification has
    // been suppressed for the first time
    Integer myID = new Integer(wi.getItem().getID());

    if (noEMail.containsKey(myID)) {
      // suppress email, and delete key
      noEMail.remove(myID);
    } else {
      try {
        // Get the item title
        String title = getItemTitle(wi);

        // Get the submitter's name
        String submitter = getSubmitterName(wi);

        // Get the collection
        Collection coll = wi.getCollection();

        String message = "";

        for (int i = 0; i < epa.length; i++) {
          Locale supportedLocale = I18nUtil.getEPersonLocale(epa[i]);
          Email email =
              ConfigurationManager.getEmail(
                  I18nUtil.getEmailFilename(supportedLocale, "submit_task"));
          email.addArgument(title);
          email.addArgument(coll.getMetadata("name"));
          email.addArgument(submitter);

          ResourceBundle messages = ResourceBundle.getBundle("Messages", supportedLocale);
          log.info("Locale des Resource Bundles: " + messages.getLocale().getDisplayName());
          switch (wi.getState()) {
            case WFSTATE_STEP1POOL:
              message = messages.getString("org.dspace.workflow.WorkflowManager.step1");

              break;

            case WFSTATE_STEP2POOL:
              message = messages.getString("org.dspace.workflow.WorkflowManager.step2");

              break;

            case WFSTATE_STEP3POOL:
              message = messages.getString("org.dspace.workflow.WorkflowManager.step3");

              break;
          }
          email.addArgument(message);
          email.addArgument(getMyDSpaceLink());
          email.addRecipient(epa[i].getEmail());
          email.send();
        }
      } catch (MessagingException e) {
        log.warn(
            LogManager.getHeader(
                c,
                "notifyGroupofTask",
                "cannot email user"
                    + " group_id"
                    + mygroup.getID()
                    + " workflow_item_id"
                    + wi.getID()));
      }
    }
  }
  public void addBody(Body body) throws WingException, SQLException {
    // Get all our parameters
    String baseURL = contextPath + "/admin/groups?administrative-continue=" + knot.getId();
    String query = parameters.getParameter("query", "");
    int page = parameters.getParameterAsInteger("page", 0);
    int highlightID = parameters.getParameterAsInteger("highlightID", -1);
    // FIXME: Bad!
    //        int resultCount = Group.searchResultCount(context, query);
    int resultCount = Group.search(context, query).length;
    Group[] groups = Group.search(context, query, page * PAGE_SIZE, PAGE_SIZE);

    // DIVISION: groups-main
    Division main =
        body.addInteractiveDivision(
            "groups-main",
            contextPath + "/admin/groups",
            Division.METHOD_POST,
            "primary administrative groups");
    main.setHead(T_main_head);

    // DIVISION: group-actions
    Division actions = main.addDivision("group-actions");
    actions.setHead(T_actions_head);

    // Browse Epeople
    List actionsList = actions.addList("actions");
    actionsList.addLabel(T_actions_create);
    actionsList.addItemXref(baseURL + "&submit_add", T_actions_create_link);
    actionsList.addLabel(T_actions_browse);
    actionsList.addItemXref(baseURL + "&query&submit_search", T_actions_browse_link);

    actionsList.addLabel(T_actions_search);
    org.dspace.app.xmlui.wing.element.Item actionItem = actionsList.addItem();
    Text queryField = actionItem.addText("query");
    if (query != null) queryField.setValue(query);
    queryField.setHelp(T_search_help);
    actionItem.addButton("submit_search").setValue(T_go);

    // DIVISION: group-search
    Division search = main.addDivision("group-search");
    search.setHead(T_search_head);

    if (resultCount > PAGE_SIZE) {
      // If there are enough results then paginate the results
      int firstIndex = page * PAGE_SIZE + 1;
      int lastIndex = page * PAGE_SIZE + groups.length;

      String nextURL = null, prevURL = null;
      if (page < (resultCount / PAGE_SIZE)) nextURL = baseURL + "&page=" + (page + 1);
      if (page > 0) prevURL = baseURL + "&page=" + (page - 1);

      search.setSimplePagination(resultCount, firstIndex, lastIndex, prevURL, nextURL);
    }

    Table table = search.addTable("groups-search-table", groups.length + 1, 1);
    Row header = table.addRow(Row.ROLE_HEADER);
    header.addCell().addContent(T_search_column1);
    header.addCell().addContent(T_search_column2);
    header.addCell().addContent(T_search_column3);
    header.addCell().addContent(T_search_column4);
    header.addCell().addContent(T_search_column5);

    for (Group group : groups) {
      Row row;
      if (group.getID() == highlightID) row = table.addRow(null, null, "highlight");
      else row = table.addRow();

      if (group.getID() > 1) {
        CheckBox select = row.addCell().addCheckBox("select_group");
        select.setLabel(new Integer(group.getID()).toString());
        select.addOption(new Integer(group.getID()).toString());
      } else {
        // Don't allow the user to remove the administrative (id:1) or
        // anonymous group (id:0)
        row.addCell();
      }

      row.addCell().addContent(group.getID());
      row.addCell().addXref(baseURL + "&submit_edit&groupID=" + group.getID(), group.getName());

      int memberCount = group.getMembers().length + group.getMemberGroups().length;
      row.addCell().addContent(memberCount == 0 ? "-" : String.valueOf(memberCount));

      Cell cell = row.addCell();
      if (FlowGroupUtils.getCollectionId(group.getName()) > -1) {
        Collection collection =
            Collection.find(context, FlowGroupUtils.getCollectionId(group.getName()));
        if (collection != null) {
          String collectionName = collection.getMetadata("name");

          if (collectionName == null) collectionName = "";
          else if (collectionName.length() > MAX_COLLECTION_NAME)
            collectionName = collectionName.substring(0, MAX_COLLECTION_NAME - 3) + "...";

          cell.addContent(collectionName + " ");

          Highlight highlight = cell.addHighlight("fade");

          highlight.addContent("[");
          highlight.addXref(
              contextPath + "/handle/" + collection.getExternalIdentifier().getCanonicalForm(),
              T_collection_link);
          highlight.addContent("]");
        }
      }
    }

    if (groups.length <= 0) {
      Cell cell = table.addRow().addCell(1, 5);
      cell.addHighlight("italic").addContent(T_no_results);
    } else {
      search.addPara().addButton("submit_delete").setValue(T_submit_delete);
    }

    search.addHidden("administrative-continue").setValue(knot.getId());
  }
예제 #9
0
  /**
   * Attach a division to the given search division named "search-results" which contains results
   * for this search query.
   *
   * @param search The search division to contain the search-results division.
   */
  protected void buildSearchResultsDivision(Division search)
      throws IOException, SQLException, WingException {
    if (getQuery().length() > 0) {

      // Perform the actual search
      performSearch();
      DSpaceObject searchScope = getScope();

      Para para = search.addPara("result-query", "result-query");

      String query = getQuery();
      int hitCount = queryResults.getHitCount();
      para.addContent(T_result_query.parameterize(query, hitCount));

      Division results = search.addDivision("search-results", "primary");

      if (searchScope instanceof Community) {
        Community community = (Community) searchScope;
        String communityName = community.getMetadata("name");
        results.setHead(T_head1_community.parameterize(communityName));
      } else if (searchScope instanceof Collection) {
        Collection collection = (Collection) searchScope;
        String collectionName = collection.getMetadata("name");
        results.setHead(T_head1_collection.parameterize(collectionName));
      } else {
        results.setHead(T_head1_none);
      }

      if (queryResults.getHitCount() > 0) {
        // Pagination variables.
        int itemsTotal = queryResults.getHitCount();
        int firstItemIndex = queryResults.getStart() + 1;
        int lastItemIndex = queryResults.getStart() + queryResults.getPageSize();
        if (itemsTotal < lastItemIndex) {
          lastItemIndex = itemsTotal;
        }
        int currentPage = (queryResults.getStart() / queryResults.getPageSize()) + 1;
        int pagesTotal = ((queryResults.getHitCount() - 1) / queryResults.getPageSize()) + 1;
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("page", "{pageNum}");
        String pageURLMask = generateURL(parameters);

        results.setMaskedPagination(
            itemsTotal, firstItemIndex, lastItemIndex, currentPage, pagesTotal, pageURLMask);

        // Look for any communities or collections in the mix
        ReferenceSet referenceSet = null;
        boolean resultsContainsBothContainersAndItems = false;

        @SuppressWarnings("unchecked") // This cast is correct
        java.util.List<String> containerHandles = queryResults.getHitHandles();
        for (String handle : containerHandles) {
          DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);

          if (resultDSO instanceof Community || resultDSO instanceof Collection) {
            if (referenceSet == null) {
              referenceSet =
                  results.addReferenceSet(
                      "search-results-repository",
                      ReferenceSet.TYPE_SUMMARY_LIST,
                      null,
                      "repository-search-results");
              // Set a heading showing that we will be listing containers that matched:
              referenceSet.setHead(T_head2);
              resultsContainsBothContainersAndItems = true;
            }
            referenceSet.addReference(resultDSO);
          }
        }

        // Look for any items in the result set.
        referenceSet = null;

        @SuppressWarnings("unchecked") // This cast is correct
        java.util.List<String> itemHandles = queryResults.getHitHandles();
        for (String handle : itemHandles) {
          DSpaceObject resultDSO = HandleManager.resolveToObject(context, handle);

          if (resultDSO instanceof Item) {
            if (referenceSet == null) {
              referenceSet =
                  results.addReferenceSet(
                      "search-results-repository",
                      ReferenceSet.TYPE_SUMMARY_LIST,
                      null,
                      "repository-search-results");
              // Only set a heading if there are both containers and items.
              if (resultsContainsBothContainersAndItems) {
                referenceSet.setHead(T_head3);
              }
            }
            referenceSet.addReference(resultDSO);
          }
        }

      } else {
        results.addPara(T_no_results);
      }
    } // Empty query
  }
예제 #10
0
  /**
   * Take a node list of collections and create the structure from them
   *
   * @param context the context of the request
   * @param collections the node list of collections to be created
   * @param parent the parent community to whom the collections belong
   * @return an Element array containing additional information about the created collections (e.g.
   *     the handle)
   */
  private static Element[] handleCollections(
      Context context, NodeList collections, Community parent) throws Exception {
    Element[] elements = new Element[collections.getLength()];

    for (int i = 0; i < collections.getLength(); i++) {
      Element element = new Element("collection");
      Collection collection = parent.createCollection();

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

      // import the rest of the metadata
      Node tn = collections.item(i);
      for (Map.Entry<String, String> entry : collectionMap.entrySet()) {
        NodeList nl = XPathAPI.selectNodeList(tn, entry.getKey());
        if (nl.getLength() == 1) {
          collection.setMetadata(entry.getValue(), getStringValue(nl.item(0)));
        }
      }

      collection.update();

      element.setAttribute("identifier", collection.getHandle());

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

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

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

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

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

      if (collection.getMetadata("license") != null) {
        Element sidebarElement = new Element("license");
        sidebarElement.setText(collection.getMetadata("license"));
        element.addContent(sidebarElement);
      }

      if (collection.getMetadata("provenance_description") != null) {
        Element sidebarElement = new Element("provenance");
        sidebarElement.setText(collection.getMetadata("provenance_description"));
        element.addContent(sidebarElement);
      }

      elements[i] = element;
    }

    return elements;
  }
  /** Display a single collection */
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (!(dso instanceof Collection)) return;

    // Set up the major variables
    Collection collection = (Collection) dso;

    // Build the collection viewer division.
    Division home = body.addDivision("collection-home", "primary repository collection");
    home.setHead(collection.getMetadata("name"));

    // The search / browse box.
    {
      Division search = home.addDivision("collection-search-browse", "secondary search-browse");

      // Search query
      Division query =
          search.addInteractiveDivision(
              "collection-search",
              contextPath + "/handle/" + collection.getHandle() + "/search",
              Division.METHOD_POST,
              "secondary search");

      Para para = query.addPara("search-query", null);
      para.addContent(T_full_text_search);
      para.addContent(" ");
      para.addText("query");
      para.addContent(" ");
      para.addButton("submit").setValue(T_go);

      // Browse by list
      Division browseDiv = search.addDivision("collection-browse", "secondary browse");
      List browse = browseDiv.addList("collection-browse", List.TYPE_SIMPLE, "collection-browse");
      browse.setHead(T_head_browse);
      String url = contextPath + "/handle/" + collection.getHandle();
      browse.addItemXref(url + "/browse-title", T_browse_titles);
      browse.addItemXref(url + "/browse-author", T_browse_authors);
      browse.addItemXref(url + "/browse-date", T_browse_dates);
    }

    // Add the refrence
    {
      Division viewer = home.addDivision("collection-view", "secondary");
      ReferenceSet mainInclude =
          viewer.addReferenceSet("collection-view", ReferenceSet.TYPE_DETAIL_VIEW);
      mainInclude.addReference(collection);
    }

    // Reciently submitted items
    {
      java.util.List<BrowseItem> items = getRecientlySubmittedIems(collection);

      Division lastSubmittedDiv =
          home.addDivision("collection-recent-submission", "secondary recent-submission");
      lastSubmittedDiv.setHead(T_head_recent_submissions);
      ReferenceSet lastSubmitted =
          lastSubmittedDiv.addReferenceSet(
              "collection-last-submitted",
              ReferenceSet.TYPE_SUMMARY_LIST,
              null,
              "recent-submissions");
      for (BrowseItem item : items) {
        lastSubmitted.addReference(item);
      }
    }
  }