public InputStream disseminate(Context context, Item item)
      throws DSpaceSwordException, SwordError, SwordServerException {
    try {
      Abdera abdera = new Abdera();
      Feed feed = abdera.newFeed();

      this.addMetadata(feed, item);

      Bundle[] originals = item.getBundles("ORIGINAL");
      for (Bundle original : originals) {
        Bitstream[] bss = original.getBitstreams();
        for (Bitstream bitstream : bss) {
          Entry entry = feed.addEntry();
          this.populateEntry(context, entry, bitstream);
        }
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      feed.writeTo(baos);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      return bais;
    } catch (SQLException e) {
      throw new DSpaceSwordException(e);
    } catch (IOException e) {
      throw new DSpaceSwordException(e);
    }
  }
  /**
   * Return this resource's children. Item's children are its bitstreams.
   *
   * @return the DAV resource[]
   * @throws SQLException the SQL exception
   */
  @Override
  protected DAVResource[] children() throws SQLException {
    // Check for overall read permission on Item
    if (!AuthorizeManager.authorizeActionBoolean(this.context, this.item, Constants.READ)) {
      return new DAVResource[0];
    }

    Vector result = new Vector();
    Bundle[] bundles = this.item.getBundles();
    for (Bundle element : bundles) {
      // check read permission on this Bundle
      if (!AuthorizeManager.authorizeActionBoolean(this.context, element, Constants.READ)) {
        continue;
      }

      Bitstream[] bitstreams = element.getBitstreams();
      for (Bitstream element0 : bitstreams) {
        String ext[] = element0.getFormat().getExtensions();
        result.add(
            new DAVBitstream(
                this.context,
                this.request,
                this.response,
                makeChildPath(
                    DAVBitstream.getPathElt(
                        element0.getSequenceID(), ext.length < 1 ? null : ext[0])),
                this.item,
                element0));
      }
    }
    return (DAVResource[]) result.toArray(new DAVResource[result.size()]);
  }
Exemple #3
0
  @Override
  public int perform(DSpaceObject dso) throws IOException {
    status = Curator.CURATE_SKIP;
    logDebugMessage("The target dso is " + dso.getName());
    if (dso instanceof Item) {
      status = Curator.CURATE_SUCCESS;
      Item item = (Item) dso;
      try {
        openSession();
      } catch (IOException ioE) {
        // no point going further - set result and error out
        closeSession();
        setResult(CONNECT_FAIL_MESSAGE);
        return Curator.CURATE_ERROR;
      }

      try {
        Bundle bundle = item.getBundles("ORIGINAL")[0];
        results = new ArrayList<String>();
        for (Bitstream bitstream : bundle.getBitstreams()) {
          InputStream inputstream = bitstream.retrieve();
          logDebugMessage("Scanning " + bitstream.getName() + " . . . ");
          int bstatus = scan(bitstream, inputstream, getItemHandle(item));
          inputstream.close();
          if (bstatus == Curator.CURATE_ERROR) {
            // no point going further - set result and error out
            setResult(SCAN_FAIL_MESSAGE);
            status = bstatus;
            break;
          }
          if (failfast && bstatus == Curator.CURATE_FAIL) {
            status = bstatus;
            break;
          } else if (bstatus == Curator.CURATE_FAIL && status == Curator.CURATE_SUCCESS) {
            status = bstatus;
          }
        }
      } catch (AuthorizeException authE) {
        throw new IOException(authE.getMessage(), authE);
      } catch (SQLException sqlE) {
        throw new IOException(sqlE.getMessage(), sqlE);
      } finally {
        closeSession();
      }

      if (status != Curator.CURATE_ERROR) {
        formatResults(item);
      }
    }
    return status;
  }
 protected void addGroupPolicyToItem(Context context, Item item, int type, Group group)
     throws AuthorizeException, SQLException {
   if (group != null) {
     authorizeService.addPolicy(context, item, type, group);
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.addPolicy(context, bundle, type, group);
       List<Bitstream> bits = bundle.getBitstreams();
       for (Bitstream bit : bits) {
         authorizeService.addPolicy(context, bit, type, group);
       }
     }
   }
 }
 protected void removeGroupItemPolicies(Context context, Item item, Group e)
     throws SQLException, AuthorizeException {
   if (e != null) {
     // Also remove any lingering authorizations from this user
     authorizeService.removeGroupPolicies(context, item, e);
     // Remove the bundle rights
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.removeGroupPolicies(context, bundle, e);
       List<Bitstream> bitstreams = bundle.getBitstreams();
       for (Bitstream bitstream : bitstreams) {
         authorizeService.removeGroupPolicies(context, bitstream, e);
       }
     }
   }
 }
  /** Add rights information. This attaches an href to the URL of the item's licence file */
  protected void addRights() throws DSpaceSWORDException {
    try {
      // work our way up to the item
      List<Bundle> bundle2bitstreams = this.bitstream.getBundles();
      if (bundle2bitstreams.isEmpty()) {
        log.error("Found orphaned bitstream: " + bitstream.getID());
        throw new DSpaceSWORDException("Orphaned bitstream discovered");
      }
      Bundle bundle = bundle2bitstreams.get(0);
      List<Item> items = bundle.getItems();
      if (items.isEmpty()) {
        log.error("Found orphaned bundle: " + bundle.getID());
        throw new DSpaceSWORDException("Orphaned bundle discovered");
      }
      Item item = items.get(0);

      // now get the licence out of the item
      SWORDUrlManager urlManager = swordService.getUrlManager();
      StringBuilder rightsString = new StringBuilder();
      List<Bundle> lbundles = item.getBundles();
      for (Bundle lbundle : lbundles) {
        if (!Constants.LICENSE_BUNDLE_NAME.equals(lbundle.getName())) {
          // skip non-license bundles
          continue;
        }
        List<Bitstream> bss = lbundle.getBitstreams();
        for (Bitstream bs : bss) {
          String url = urlManager.getBitstreamUrl(bs);
          rightsString.append(url).append(" ");
        }
      }

      Rights rights = new Rights();
      rights.setContent(rightsString.toString());
      rights.setType(ContentType.TEXT);
      entry.setRights(rights);
      log.debug("Added rights entry to entity");
    } catch (SQLException e) {
      log.error("caught exception: ", e);
      throw new DSpaceSWORDException(e);
    }
  }
 protected void removeUserItemPolicies(Context context, Item item, EPerson e)
     throws SQLException, AuthorizeException {
   if (e != null) {
     // Also remove any lingering authorizations from this user
     authorizeService.removeEPersonPolicies(context, item, e);
     // Remove the bundle rights
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.removeEPersonPolicies(context, bundle, e);
       List<Bitstream> bitstreams = bundle.getBitstreams();
       for (Bitstream bitstream : bitstreams) {
         authorizeService.removeEPersonPolicies(context, bitstream, e);
       }
     }
     // Ensure that the submitter always retains his resource policies
     if (e.getID().equals(item.getSubmitter().getID())) {
       grantSubmitterReadPolicies(context, item);
     }
   }
 }
  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());
  }