Esempio n. 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"));
      }
    }
  }
Esempio n. 2
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;
  }
Esempio n. 3
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
  }
  public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    int communityID = parameters.getParameterAsInteger("communityID", -1);
    Community parentCommunity = Community.find(context, communityID);

    // DIVISION: main
    Division main =
        body.addInteractiveDivision(
            "create-collection",
            contextPath + "/admin/collection",
            Division.METHOD_MULTIPART,
            "primary administrative collection");
    main.setHead(T_main_head.parameterize(parentCommunity.getMetadata("name")));

    // The grand list of metadata options
    List metadataList = main.addList("metadataList", "form");

    // collection name
    metadataList.addLabel(T_label_name);
    Text name = metadataList.addItem().addText("name");
    name.setSize(40);

    // short description
    metadataList.addLabel(T_label_short_description);
    Text short_description = metadataList.addItem().addText("short_description");
    short_description.setSize(40);

    // introductory text
    metadataList.addLabel(T_label_introductory_text);
    TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
    introductory_text.setSize(6, 40);

    // copyright text
    metadataList.addLabel(T_label_copyright_text);
    TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
    copyright_text.setSize(6, 40);

    // legacy sidebar text; may or may not be used for news
    metadataList.addLabel(T_label_side_bar_text);
    TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
    side_bar_text.setSize(6, 40);

    // license text
    metadataList.addLabel(T_label_license);
    TextArea license = metadataList.addItem().addTextArea("license");
    license.setSize(6, 40);

    // provenance description
    metadataList.addLabel(T_label_provenance_description);
    TextArea provenance_description = metadataList.addItem().addTextArea("provenance_description");
    provenance_description.setSize(6, 40);

    // the row to upload a new logo
    metadataList.addLabel(T_label_logo);
    metadataList.addItem().addFile("logo");

    Para buttonList = main.addPara();
    buttonList.addButton("submit_save").setValue(T_submit_save);
    buttonList.addButton("submit_cancel").setValue(T_submit_cancel);

    main.addHidden("administrative-continue").setValue(knot.getId());
  }