private void addAdministratorOnlyButton(Cell cell, String buttonName, Message buttonLabel)
     throws WingException, SQLException {
   Button button = cell.addButton(buttonName);
   button.setValue(buttonLabel);
   if (!AuthorizeManager.isAdmin(context)) {
     // Only admins can create or delete
     button.setDisabled();
     cell.addHighlight("fade").addContent(T_sysadmins_only);
   }
 }
Ejemplo n.º 2
0
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    Request request = ObjectModelHelper.getRequest(objectModel);
    boolean help = false, error = false;
    if (request.getParameter("help") != null) {
      help = true;
    }
    if (request.getParameter("error") != null) {
      error = true;
    }

    Division div = body.addInteractiveDivision("test", "", "post", "primary");
    div.setHead("Inline form test");
    div.addPara(
        "There are two options you can use to control how this page is generated. First is the help parameter, if this is present then help text will be provided for all fields. Next is the error parameter, if it is provided then all fields will be generated in error conditions.");

    if (help) {
      div.addPara().addXref(makeURL(false, error), "Turn help OFF");
    } else {
      div.addPara().addXref(makeURL(true, error), "Turn help ON");
    }

    if (error) {
      div.addPara().addXref(makeURL(help, false), "Turn errors OFF");
    } else {
      div.addPara().addXref(makeURL(help, true), "Turn errors ON");
    }

    Division suited = body.addDivision("suited");
    suited.setHead("Fields suited towards being used inline");

    suited.addPara(
        "Below are a list of embedded fields that are normally considered usefully in an inline context.");

    // Text field
    Para p = suited.addPara();
    p.addContent("This is a plain 'Text' field, ");
    Text text = p.addText("text");
    text.setLabel("Text");
    if (help) {
      text.setHelp("This is helpfull text.");
    }
    if (error) {
      text.addError("This field is in error.");
    }
    text.setValue("Current raw value");
    p.addContent(", embedded in a paragraph.");

    // Single Checkbox field
    p = suited.addPara();
    p.addContent("This is a singe 'CheckBox' field, ");
    CheckBox checkBox = p.addCheckBox("yes-or-no");
    if (help) {
      checkBox.setHelp("Select either yes or no.");
    }
    if (error) {
      checkBox.addError("You are incorrect, try again.");
    }
    checkBox.setLabel("Yes or no");
    checkBox.addOption("yes");
    p.addContent(", embedded in a paragraph.");

    // File
    p = suited.addPara();
    p.addContent("This is a 'File' field, ");
    File file = p.addFile("file");
    file.setLabel("File");
    if (help) {
      file.setHelp("Upload a file.");
    }
    if (error) {
      file.addError("This field is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    // Select (single)
    p = suited.addPara();
    p.addContent("This is single 'Select' (aka dropdown) field, ");
    Select select = p.addSelect("select");
    select.setLabel("Select (single)");
    if (help) {
      select.setHelp("Select one of the options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    p.addContent(", embedded in a paragraph.");

    // Button
    p = suited.addPara();
    p.addContent("This is a 'Button' field, ");
    Button button = p.addButton("button");
    button.setLabel("Button");
    button.setValue("When you touch me I do things, lots of things");
    if (help) {
      button.setHelp("Submit buttons allow the user to submit the form.");
    }
    if (error) {
      button.addError("This button is in error.");
    }
    p.addContent(", embedded in a paragraph.");

    Division unsuited = body.addDivision("unsuited");
    unsuited.setHead("Fields typicaly unsuited towards being used inline");

    unsuited.addPara(
        "Below are a list of embedded fields that are normally considered useless in an inline context. This is because there widgets normally cross multiple lines making them hard to render inline. However these are all legal, but perhaps not advisable, and in some circumstances may be needed.");

    // Text Area Field
    p = unsuited.addPara();
    p.addContent("This is a 'Text Area' field, ");
    TextArea textArea = p.addTextArea("textarea");
    textArea.setLabel("Text Area");
    if (help) {
      textArea.setHelp("This is helpfull text.");
    }
    if (error) {
      textArea.addError("This field is in error.");
    }
    textArea.setValue("This is the raw value");
    p.addContent(", embedded in a paragraph.");

    // Multi-option Checkbox field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'CheckBox' field, ");
    checkBox = p.addCheckBox("fruit");
    if (help) {
      checkBox.setHelp("Select all the fruits that you like to eat");
    }
    if (error) {
      checkBox.addError("You are incorrect you actualy do like Tootse Rolls.");
    }
    checkBox.setLabel("fruits");
    checkBox.addOption("apple", "Apples");
    checkBox.addOption(true, "orange", "Oranges");
    checkBox.addOption("pear", "Pears");
    checkBox.addOption("tootsie", "Tootsie Roll");
    checkBox.addOption(true, "cherry", "Cherry");
    p.addContent(", embedded in a paragraph.");

    // multi-option Radio field
    p = unsuited.addPara();
    p.addContent("This is a multi-option 'Radio' field, ");
    Radio radio = p.addRadio("sex");
    radio.setLabel("Football colors");
    if (help) {
      radio.setHelp("Select the colors of the best (college) football team.");
    }
    if (error) {
      radio.addError("Error, Maroon & White is the only acceptable answer.");
    }
    radio.addOption("ut", "Burnt Orange & White");
    radio.addOption(true, "tamu", "Maroon & White");
    radio.addOption("ttu", "Tech Red & Black");
    radio.addOption("baylor", "Green & Gold");
    radio.addOption("rice", "Blue & Gray");
    radio.addOption("uh", "Scarlet Red & Albino White");
    p.addContent(", embedded in a paragraph.");

    // Select (multiple)
    p = unsuited.addPara();
    p.addContent("This is multiple 'Select' field, ");
    select = p.addSelect("multi-select");
    select.setLabel("Select (multiple)");
    select.setMultiple();
    select.setSize(4);
    if (help) {
      select.setHelp("Select one or more options");
    }
    if (error) {
      select.addError("This field is in error.");
    }
    select.addOption("one", "uno");
    select.addOption("two", "dos");
    select.addOption("three", "tres");
    select.addOption("four", "cuatro");
    select.addOption("five", "cinco");
    select.setOptionSelected("one");
    select.setOptionSelected("three");
    select.setOptionSelected("five");
    p.addContent(", embedded in a paragraph.");

    // Composite
    p = unsuited.addPara();
    p.addContent("This is a 'Composite' field of two text fields, ");
    Composite composite = p.addComposite("composite-2text");
    composite.setLabel("Composite (two text fields)");
    if (help) {
      composite.setHelp("I am the help for the entire composite");
    }
    if (error) {
      composite.addError("Just the composite is in error");
    }
    text = composite.addText("partA");
    text.setLabel("Part A");
    text.setValue("Value for part A");
    if (help) {
      text.setHelp("Part A");
    }
    text = composite.addText("partB");
    text.setLabel("Part B");
    text.setValue("Value for part B");
    if (help) {
      text.setHelp("Part B");
    }
    p.addContent(", embedded in a paragraph.");
  }
Ejemplo n.º 3
0
  public void addBody(Body body) throws SAXException, WingException, SQLException {
    // Get our parameters and state;
    UUID collectionID = UUID.fromString(parameters.getParameter("collectionID", null));
    Collection collection = collectionService.find(context, collectionID);

    List<Item> items = getMappedItems(collection);

    // DIVISION: browse-items
    Division div =
        body.addInteractiveDivision(
            "browse-items",
            contextPath + "/admin/mapper",
            Division.METHOD_GET,
            "primary administrative mapper");
    div.setHead(T_head1);

    if (authorizeService.authorizeActionBoolean(context, collection, Constants.REMOVE)) {
      Para actions = div.addPara();
      actions.addButton("submit_unmap").setValue(T_submit_unmap);
      actions.addButton("submit_return").setValue(T_submit_return);
    } else {
      Para actions = div.addPara();
      Button button = actions.addButton("submit_unmap");
      button.setValue(T_submit_unmap);
      button.setDisabled();
      actions.addButton("submit_return").setValue(T_submit_return);

      div.addPara().addHighlight("fade").addContent(T_no_remove);
    }

    Table table = div.addTable("browse-items-table", 1, 1);

    Row header = table.addRow(Row.ROLE_HEADER);
    header.addCellContent(T_column1);
    header.addCellContent(T_column2);
    header.addCellContent(T_column3);
    header.addCellContent(T_column4);

    for (Item item : items) {
      String itemID = String.valueOf(item.getID());
      Collection owningCollection = item.getOwningCollection();
      String owning = owningCollection.getName();
      String author = "unknown";
      List<MetadataValue> dcAuthors =
          itemService.getMetadata(
              item, MetadataSchema.DC_SCHEMA, "contributor", Item.ANY, Item.ANY);
      if (dcAuthors != null && dcAuthors.size() >= 1) {
        author = dcAuthors.get(0).getValue();
      }

      String title = "untitled";
      List<MetadataValue> dcTitles =
          itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
      if (dcTitles != null && dcTitles.size() >= 1) {
        title = dcTitles.get(0).getValue();
      }

      String url = contextPath + "/handle/" + item.getHandle();

      Row row = table.addRow();

      CheckBox select = row.addCell().addCheckBox("itemID");
      select.setLabel("Select");
      select.addOption(itemID);

      row.addCellContent(owning);
      row.addCell().addXref(url, author);
      row.addCell().addXref(url, title);
    }

    if (authorizeService.authorizeActionBoolean(context, collection, Constants.REMOVE)) {
      Para actions = div.addPara();
      actions.addButton("submit_unmap").setValue(T_submit_unmap);
      actions.addButton("submit_return").setValue(T_submit_return);
    } else {
      Para actions = div.addPara();
      Button button = actions.addButton("submit_unmap");
      button.setValue(T_submit_unmap);
      button.setDisabled();
      actions.addButton("submit_return").setValue(T_submit_return);

      div.addPara().addHighlight("fade").addContent(T_no_remove);
    }

    div.addHidden("administrative-continue").setValue(knot.getId());
  }
  public void addBody(Body body) throws SQLException, WingException {
    // Get our parameters and state
    int itemID = parameters.getParameterAsInteger("itemID", -1);
    Item item = Item.find(context, itemID);
    String baseURL = contextPath + "/admin/item?administrative-continue=" + knot.getId();

    // DIVISION: main div
    Division main =
        body.addInteractiveDivision(
            "edit-item-status",
            contextPath + "/admin/item",
            Division.METHOD_POST,
            "primary administrative item");
    main.setHead(T_option_head);

    // LIST: options
    List options = main.addList("options", List.TYPE_SIMPLE, "horizontal");
    options.addItem().addXref(baseURL + "&submit_status", T_option_status);
    options
        .addItem()
        .addHighlight("bold")
        .addXref(baseURL + "&submit_bitstreams", T_option_bitstreams);
    options.addItem().addXref(baseURL + "&submit_metadata", T_option_metadata);
    options.addItem().addXref(baseURL + "&view_item", T_option_view);

    // TABLE: Bitstream summary
    Table files = main.addTable("editItemBitstreams", 1, 1);

    files.setHead(T_head1);

    Row header = files.addRow(Row.ROLE_HEADER);
    header.addCellContent(T_column1);
    header.addCellContent(T_column2);
    header.addCellContent(T_column3);
    header.addCellContent(T_column4);
    header.addCellContent(T_column5);

    Bundle[] bundles = item.getBundles();

    for (Bundle bundle : bundles) {

      Cell bundleCell = files.addRow().addCell(1, 5);
      bundleCell.addContent(T_bundle_label.parameterize(bundle.getName()));

      Bitstream[] bitstreams = bundle.getBitstreams();

      for (Bitstream bitstream : bitstreams) {
        boolean primary = (bundle.getPrimaryBitstreamID() == bitstream.getID());
        String name = bitstream.getName();

        if (name != null && name.length() > 50) {
          // If the fiel name is too long the shorten it so that it will display nicely.
          String shortName = name.substring(0, 15);
          shortName += " ... ";
          shortName += name.substring(name.length() - 25, name.length());
          name = shortName;
        }

        String description = bitstream.getDescription();
        String format = null;
        BitstreamFormat bitstreamFormat = bitstream.getFormat();
        if (bitstreamFormat != null) format = bitstreamFormat.getShortDescription();
        String editURL =
            contextPath
                + "/admin/item?administrative-continue="
                + knot.getId()
                + "&bitstreamID="
                + bitstream.getID()
                + "&submit_edit";
        String viewURL =
            contextPath + "/bitstream/id/" + bitstream.getID() + "/" + bitstream.getName();

        Row row = files.addRow();
        CheckBox remove = row.addCell().addCheckBox("remove");
        remove.setLabel("remove");
        remove.addOption(bundle.getID() + "/" + bitstream.getID());
        if (!AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE)) {
          remove.setDisabled();
        }

        if (AuthorizeManager.authorizeActionBoolean(context, bitstream, Constants.WRITE)) {
          // The user can edit the bitstream give them a link.
          Cell cell = row.addCell();
          cell.addXref(editURL, name);
          if (primary) cell.addXref(editURL, T_primary_label);

          row.addCell().addXref(editURL, description);
          row.addCell().addXref(editURL, format);
        } else {
          // The user can't edit the bitstream just show them it.
          Cell cell = row.addCell();
          cell.addContent(name);
          if (primary) cell.addContent(T_primary_label);

          row.addCell().addContent(description);
          row.addCell().addContent(format);
        }

        Highlight highlight = row.addCell().addHighlight("fade");
        highlight.addContent("[");
        highlight.addXref(viewURL, T_view_link);
        highlight.addContent("]");
      }
    }

    if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.ADD)) {
      Cell cell = files.addRow().addCell(1, 5);
      cell.addXref(
          contextPath + "/admin/item?administrative-continue=" + knot.getId() + "&submit_add",
          T_submit_add);
    } else {
      Cell cell = files.addRow().addCell(1, 5);
      cell.addHighlight("fade").addContent(T_no_upload);
    }

    // PARA: actions
    Para actions = main.addPara("editItemActionsP", "editItemActionsP");
    if (AuthorizeManager.authorizeActionBoolean(context, item, Constants.REMOVE))
      actions.addButton("submit_delete").setValue(T_submit_delete);
    else {
      Button button = actions.addButton("submit_delete");
      button.setValue(T_submit_delete);
      button.setDisabled();

      main.addPara().addHighlight("fade").addContent(T_no_remove);
    }
    actions.addButton("submit_return").setValue(T_submit_return);

    main.addHidden("administrative-continue").setValue(knot.getId());
  }
Ejemplo n.º 5
0
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // If we are actually editing information of an uploaded file,
    // then display that body instead!
    if (this.editFile != null) {
      editFile.addBody(body);
      return;
    }

    // Get a list of all files in the original bundle
    Item item = submission.getItem();
    Collection collection = submission.getCollection();
    String actionURL =
        contextPath + "/handle/" + collection.getHandle() + "/submit/" + knot.getId() + ".continue";
    boolean disableFileEditing =
        (submissionInfo.isInWorkflow())
            && !ConfigurationManager.getBooleanProperty("workflow", "reviewer.file-edit");
    Bundle[] bundles = item.getBundles("ORIGINAL");
    Bitstream[] bitstreams = new Bitstream[0];
    if (bundles.length > 0) {
      bitstreams = bundles[0].getBitstreams();
    }

    // Part A:
    //  First ask the user if they would like to upload a new file (may be the first one)
    Division div =
        body.addInteractiveDivision(
            "submit-upload", actionURL, Division.METHOD_MULTIPART, "primary submission");
    div.setHead(T_submission_head);
    addSubmissionProgressList(div);

    List upload = null;
    if (!disableFileEditing) {
      // Only add the upload capabilities for new item submissions
      upload = div.addList("submit-upload-new", List.TYPE_FORM);
      upload.setHead(T_head);
      addRioxxVersionSection(upload, item);

      File file = upload.addItem().addFile("file");
      file.setLabel(T_file);
      file.setHelp(T_file_help);
      file.setRequired();

      // if no files found error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_NO_FILES_ERROR) {
        file.addError(T_file_error);
      }

      // if an upload error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_UPLOAD_ERROR) {
        file.addError(T_upload_error);
      }

      // if virus checking was attempted and failed in error then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_VIRUS_CHECKER_UNAVAILABLE) {
        file.addError(T_virus_checker_error);
      }

      // if virus checking was attempted and a virus found then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_CONTAINS_VIRUS) {
        file.addError(T_virus_error);
      }

      Text description = upload.addItem().addText("description");
      description.setLabel(T_description);
      description.setHelp(T_description_help);

      Button uploadSubmit = upload.addItem().addButton("submit_upload");
      uploadSubmit.setValue(T_submit_upload);
    }

    make_sherpaRomeo_submission(item, div);

    // Part B:
    //  If the user has already uploaded files provide a list for the user.
    if (bitstreams.length > 0 || disableFileEditing) {
      Table summary = div.addTable("submit-upload-summary", (bitstreams.length * 2) + 2, 7);
      summary.setHead(T_head2);

      Row header = summary.addRow(Row.ROLE_HEADER);
      header.addCellContent(T_column0); // primary bitstream
      header.addCellContent(T_column1); // select checkbox
      header.addCellContent(T_column2); // file name
      header.addCellContent(T_column3); // size
      header.addCellContent(T_column4); // description
      header.addCellContent(T_column5); // format
      header.addCellContent(T_column6); // edit button

      for (Bitstream bitstream : bitstreams) {
        int id = bitstream.getID();
        String name = bitstream.getName();
        String url = makeBitstreamLink(item, bitstream);
        long bytes = bitstream.getSize();
        String desc = bitstream.getDescription();
        String algorithm = bitstream.getChecksumAlgorithm();
        String checksum = bitstream.getChecksum();

        Row row = summary.addRow();

        // Add radio-button to select this as the primary bitstream
        Radio primary = row.addCell().addRadio("primary_bitstream_id");
        primary.addOption(String.valueOf(id));

        // If this bitstream is already marked as the primary bitstream
        // mark it as such.
        if (bundles[0].getPrimaryBitstreamID() == id) {
          primary.setOptionSelected(String.valueOf(id));
        }

        if (!disableFileEditing) {
          // Workflow users can not remove files.
          CheckBox remove = row.addCell().addCheckBox("remove");
          remove.setLabel("remove");
          remove.addOption(id);
        } else {
          row.addCell();
        }

        row.addCell().addXref(url, name);
        row.addCellContent(bytes + " bytes");
        if (desc == null || desc.length() == 0) {
          row.addCellContent(T_unknown_name);
        } else {
          row.addCellContent(desc);
        }

        BitstreamFormat format = bitstream.getFormat();
        if (format == null) {
          row.addCellContent(T_unknown_format);
        } else {
          int support = format.getSupportLevel();
          Cell cell = row.addCell();
          cell.addContent(format.getMIMEType());
          cell.addContent(" ");
          switch (support) {
            case 1:
              cell.addContent(T_supported);
              break;
            case 2:
              cell.addContent(T_known);
              break;
            case 3:
              cell.addContent(T_unsupported);
              break;
          }
        }

        Button edit = row.addCell().addButton("submit_edit_" + id);
        edit.setValue(T_submit_edit);

        Row checksumRow = summary.addRow();
        checksumRow.addCell();
        Cell checksumCell = checksumRow.addCell(null, null, 0, 6, null);
        checksumCell.addHighlight("bold").addContent(T_checksum);
        checksumCell.addContent(" ");
        checksumCell.addContent(algorithm + ":" + checksum);
      }

      if (!disableFileEditing) {
        // Workflow users can not remove files.
        Row actionRow = summary.addRow();
        actionRow.addCell();
        Button removeSeleceted =
            actionRow.addCell(null, null, 0, 6, null).addButton("submit_remove_selected");
        removeSeleceted.setValue(T_submit_remove);
      }

      upload = div.addList("submit-upload-new-part2", List.TYPE_FORM);
    }

    // Part C:
    // add standard control/paging buttons
    addControlButtons(upload);
  }
Ejemplo n.º 6
0
  public void addTablePolicies(Division parent, DSpaceObject dso, Collection owningCollection)
      throws WingException, SQLException {
    if (!isAdvancedFormEnabled) {
      return;
    }
    Division div = parent.addDivision("access-existing-policies");
    div.setHead(T_head_policies_table);
    div.addPara(T_policies_help.parameterize(owningCollection));

    java.util.List<ResourcePolicy> resourcePolicies =
        authorizeService.findPoliciesByDSOAndType(context, dso, ResourcePolicy.TYPE_CUSTOM);

    if (resourcePolicies.isEmpty()) {
      div.addPara(T_no_policies);
      return;
    }

    int cols = resourcePolicies.size();
    if (cols == 0) cols = 1;
    Table policies = div.addTable("policies", 6, cols);
    Row header = policies.addRow(Row.ROLE_HEADER);

    header.addCellContent(T_column0); // name
    header.addCellContent(T_column1); // action
    header.addCellContent(T_column2); // group
    header.addCellContent(T_column3); // start_date
    header.addCellContent(T_column4); // end_date

    for (ResourcePolicy rp : resourcePolicies) {
      int id = rp.getID();

      String name = "";
      if (rp.getRpName() != null) name = rp.getRpName();

      String action = resourcePolicyService.getActionText(rp);

      // if it is the default policy for the Submitter don't show it.
      if (dso instanceof org.dspace.content.Item) {
        org.dspace.content.Item item = (org.dspace.content.Item) dso;
        if (rp.getEPerson() != null) {
          if (item.getSubmitter().equals(rp.getEPerson())) continue;
        }
      }

      String group = "";
      if (rp.getGroup() != null) group = rp.getGroup().getName();

      Row row = policies.addRow();

      row.addCellContent(name);
      row.addCellContent(action);
      row.addCellContent(group);

      // start
      String startDate = "";
      if (rp.getStartDate() != null) {
        startDate = DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd");
      }
      row.addCellContent(startDate);

      // endDate
      String endDate = "";
      if (rp.getEndDate() != null) {
        endDate = DateFormatUtils.format(rp.getEndDate(), "yyyy-MM-dd");
      }
      row.addCellContent(endDate);

      Button edit = row.addCell().addButton("submit_edit_edit_policies_" + id);
      edit.setValue(T_table_submit_edit);

      Button delete = row.addCell().addButton("submit_delete_edit_policies_" + id);
      delete.setValue(T_table_submit_delete);
    }
  }