/** Add links associated with this item. */
  protected void addLinks() throws DSpaceSWORDException {
    // if this is a deposit which is no op we can't do anything here
    if (this.deposit != null && this.deposit.isNoOp()) {
      return;
    }

    // get the things we need out of the service
    SWORDUrlManager urlManager = swordService.getUrlManager();

    String bsurl = urlManager.getBitstreamUrl(this.bitstream);
    BitstreamFormat bf;
    try {
      bf = this.bitstream.getFormat(swordService.getContext());
    } catch (SQLException e) {
      log.error("Exception caught: ", e);
      throw new DSpaceSWORDException(e);
    }
    String format = "application/octet-stream";
    if (bf != null) {
      format = bf.getMIMEType();
    }

    Link link = new Link();
    link.setType(format);
    link.setHref(bsurl);
    link.setRel("alternate");
    entry.addLink(link);

    log.debug("Added link entity to entry for url " + bsurl);
  }
  private void populateEntry(Context context, Entry entry, Bitstream bitstream)
      throws DSpaceSwordException {
    BitstreamFormat format = bitstream.getFormat();
    String contentType = null;
    if (format != null) {
      contentType = format.getMIMEType();
    }

    SwordUrlManager urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context);
    String bsUrl = urlManager.getBitstreamUrl(bitstream);

    entry.setId(bsUrl);
    entry.setTitle(bitstream.getName());
    String desc = bitstream.getDescription();
    if ("".equals(desc) || desc == null) {
      desc = bitstream.getName();
    }
    entry.setSummary(desc);
    entry.setUpdated(new Date()); // required, though content is spurious

    // add an edit-media link for the bitstream ...
    Abdera abdera = new Abdera();
    Link link = abdera.getFactory().newLink();
    link.setHref(urlManager.getActionableBitstreamUrl(bitstream));
    link.setMimeType(contentType);
    link.setRel("edit-media");
    entry.addLink(link);

    // set the content of the bitstream
    entry.setContent(new IRI(bsUrl), contentType);
  }
  /** Set the content type that DSpace received. */
  protected void addContentElement() throws DSpaceSWORDException {
    try {
      // get the things we need out of the service
      SWORDUrlManager urlManager = swordService.getUrlManager();

      // if this is a deposit which is no op we can't do anything here
      if (this.deposit != null && this.deposit.isNoOp()) {
        return;
      }

      String bsurl = urlManager.getBitstreamUrl(this.bitstream);
      BitstreamFormat bf = null;
      try {
        bf = this.bitstream.getFormat(swordService.getContext());
      } catch (SQLException e) {
        log.error("Exception caught: ", e);
        throw new DSpaceSWORDException(e);
      }
      String format = "application/octet-stream";
      if (bf != null) {
        format = bf.getMIMEType();
      }

      Content con = new Content();
      con.setType(format);
      con.setSource(bsurl);
      entry.setContent(con);

      log.debug("Adding content element with url=" + bsurl);
    } catch (InvalidMediaTypeException e) {
      log.error("caught and swallowed exception: ", e);
      // do nothing; we'll live without the content type declaration!
    }
  }
 /** Test of findUnknown method, of class BitstreamFormat. */
 @Test
 public void testFindUnknown() throws SQLException {
   BitstreamFormat found = BitstreamFormat.findUnknown(context);
   assertThat("testFindUnknown 0", found, notNullValue());
   assertThat("testFindUnknown 1", found.getShortDescription(), equalTo("Unknown"));
   assertFalse("testFindUnknown 2", found.isInternal());
   assertThat("testFindUnknown 3", found.getSupportLevel(), equalTo(0));
 }
  /** Test of setInternal method, of class BitstreamFormat. */
  @Test
  public void testSetInternal() {
    assertFalse("testSetInternal 0", bf.isInternal());

    bf.setInternal(true);

    assertThat("testSetInternal 1", bf.isInternal(), equalTo(true));
  }
  /** Test of setShortDescription method, of class BitstreamFormat. */
  @Test
  public void testSetShortDescription() throws SQLException {
    String desc = "short";
    bf.setShortDescription(desc);

    assertThat("testSetShortDescription 0", bf.getShortDescription(), notNullValue());
    assertThat("testSetShortDescription 1", bf.getShortDescription(), not(equalTo("")));
    assertThat("testSetShortDescription 2", bf.getShortDescription(), equalTo(desc));
  }
  /** Test of setMIMEType method, of class BitstreamFormat. */
  @Test
  public void testSetMIMEType() {
    String mime = "text/plain";
    bf.setMIMEType(mime);

    assertThat("testSetMIMEType 0", bf.getMIMEType(), notNullValue());
    assertThat("testSetMIMEType 1", bf.getMIMEType(), not(equalTo("")));
    assertThat("testSetMIMEType 2", bf.getMIMEType(), equalTo(mime));
  }
  /** Test of setDescription method, of class BitstreamFormat. */
  @Test
  public void testSetDescription() {
    String desc = "long description stored here";
    bf.setDescription(desc);

    assertThat("testSetDescription 0", bf.getDescription(), notNullValue());
    assertThat("testSetDescription 1", bf.getDescription(), not(equalTo("")));
    assertThat("testSetDescription 2", bf.getDescription(), equalTo(desc));
  }
 /** Test of getSupportLevelID method, of class BitstreamFormat. */
 @Test
 public void testGetSupportLevelIDValid() {
   int id1 = BitstreamFormat.getSupportLevelID("UNKNOWN");
   assertThat("testGetSupportLevelIDValid 0", id1, equalTo(BitstreamFormat.UNKNOWN));
   int id2 = BitstreamFormat.getSupportLevelID("KNOWN");
   assertThat("testGetSupportLevelIDValid 1", id2, equalTo(BitstreamFormat.KNOWN));
   int id3 = BitstreamFormat.getSupportLevelID("SUPPORTED");
   assertThat("testGetSupportLevelIDValid 2", id3, equalTo(BitstreamFormat.SUPPORTED));
 }
  /** Test of findNonInternal method, of class BitstreamFormat. */
  @Test
  public void testFindNonInternal() throws SQLException {

    BitstreamFormat[] found = BitstreamFormat.findNonInternal(context);
    assertThat("testFindNonInternal 0", found, notNullValue());
    int i = 0;
    for (BitstreamFormat b : found) {
      i++;
      assertFalse(
          "testFindNonInternal " + i + " (" + b.getShortDescription() + ")", b.isInternal());
    }
  }
 /**
  * This method will be run before every test as per @Before. It will initialize resources required
  * for the tests.
  *
  * <p>Other methods can be annotated with @Before here or in subclasses but no execution order is
  * guaranteed
  */
 @Before
 @Override
 public void init() {
   super.init();
   try {
     bf = BitstreamFormat.find(context, 5);
     bunknown = BitstreamFormat.findUnknown(context);
   } catch (SQLException ex) {
     log.error("SQL Error in init", ex);
     fail("SQL Error in init: " + ex.getMessage());
   }
 }
Beispiel #12
0
  /**
   * Process input from get file type page
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by UI-related code! (if STATUS_COMPLETE or
   *     0 is returned, no errors occurred!)
   */
  protected int processSaveFileFormat(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    if (subInfo.getBitstream() != null) {
      // Did the user select a format?
      int typeID = Util.getIntParameter(request, "format");

      BitstreamFormat format = BitstreamFormat.find(context, typeID);

      if (format != null) {
        subInfo.getBitstream().setFormat(format);
      } else {
        String userDesc = request.getParameter("format_description");

        subInfo.getBitstream().setUserFormatDescription(userDesc);
      }

      // update database
      subInfo.getBitstream().update();
    } else {
      return STATUS_INTEGRITY_ERROR;
    }

    return STATUS_COMPLETE;
  }
  public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    // Get all our parameters
    String idsString = parameters.getParameter("formatIDs", null);

    ArrayList<BitstreamFormat> formats = new ArrayList<BitstreamFormat>();
    for (String id : idsString.split(",")) {
      BitstreamFormat format = BitstreamFormat.find(context, Integer.valueOf(id));
      formats.add(format);
    }

    // DIVISION: bitstream-format-confirm-delete
    Division deleted =
        body.addInteractiveDivision(
            "bitstream-format-confirm-delete",
            contextPath + "/admin/format-registry",
            Division.METHOD_POST,
            "primary administrative format-registry");
    deleted.setHead(T_head);
    deleted.addPara(T_para1);

    Table table = deleted.addTable("format-confirm-delete", formats.size() + 1, 3);
    Row header = table.addRow(Row.ROLE_HEADER);
    header.addCell().addContent(T_column1);
    header.addCell().addContent(T_column2);
    header.addCell().addContent(T_column3);

    for (BitstreamFormat format : formats) {
      if (format == null) {
        continue;
      }

      String formatID = String.valueOf(format.getID());
      String mimetype = format.getMIMEType();
      String name = format.getShortDescription();

      Row row = table.addRow();
      row.addCell().addContent(formatID);
      row.addCell().addContent(mimetype);
      row.addCell().addContent(name);
    }
    Para buttons = deleted.addPara();
    buttons.addButton("submit_confirm").setValue(T_submit_delete);
    buttons.addButton("submit_cancel").setValue(T_submit_cancel);

    deleted.addHidden("administrative-continue").setValue(knot.getId());
  }
  /** Test of delete method, of class BitstreamFormat. */
  @Test
  public void testDeleteAdmin() throws SQLException, AuthorizeException {

    new NonStrictExpectations() {
      AuthorizeManager authManager;
      BitstreamFormat unknown;

      {
        AuthorizeManager.isAdmin((Context) any);
        result = true;
      }
    };

    bf.delete();
    BitstreamFormat b = BitstreamFormat.find(context, 5);
    assertThat("testDeleteAdmin 0", b, nullValue());
  }
  /** Test of update method, of class BitstreamFormat. */
  @Test
  public void testUpdateAdmin() throws SQLException, AuthorizeException {

    new NonStrictExpectations() {
      AuthorizeManager authManager;

      {
        AuthorizeManager.isAdmin((Context) any);
        result = true;
      }
    };

    String desc = "Test description";
    bf.setDescription(desc);
    bf.update();

    BitstreamFormat b = BitstreamFormat.find(context, 5);
    assertThat("testUpdateAdmin 0", b.getDescription(), equalTo(desc));
  }
  /** Test of findAll method, of class BitstreamFormat. */
  @Test
  public void testFindAll() throws SQLException {

    BitstreamFormat[] found = BitstreamFormat.findAll(context);
    assertThat("testFindAll 0", found, notNullValue());

    // check pos 0 is Unknown
    assertThat("testFindAll 1", found[0].getShortDescription(), equalTo("Unknown"));
    assertFalse("testFindAll 2", found[0].isInternal());
    assertThat("testFindAll 3", found[0].getSupportLevel(), equalTo(0));

    boolean added = false;
    for (BitstreamFormat bsf : found) {
      if (bsf.equals(bf)) {
        added = true;
      }
    }
    assertTrue("testFindAll 4", added);
  }
Beispiel #17
0
 // utility to grovel bitstream formats..
 private static void setFormatToMIMEType(Context context, Bitstream bs, String mimeType)
     throws SQLException {
   BitstreamFormat bf[] = BitstreamFormat.findNonInternal(context);
   for (int i = 0; i < bf.length; ++i) {
     if (bf[i].getMIMEType().equalsIgnoreCase(mimeType)) {
       bs.setFormat(bf[i]);
       break;
     }
   }
 }
  protected BitstreamFormat getFormat(Context context, String fileName) throws SQLException {
    String fext = null;
    int lastDot = fileName.lastIndexOf(".");
    if (lastDot > -1) {
      fext = fileName.substring(lastDot + 1);
    }

    if (fext == null) {
      return null;
    }

    for (BitstreamFormat format : BitstreamFormat.findAll(context)) {
      String[] extensions = format.getExtensions();
      for (String ext : extensions) {
        if (ext.equals(fext)) {
          return format;
        }
      }
    }
    return null;
  }
  /** Test of findByMIMEType method, of class BitstreamFormat. */
  @Test
  public void testFindByMIMEType() throws SQLException {
    BitstreamFormat found = BitstreamFormat.findByMIMEType(context, "text/plain");
    assertThat("testFindByMIMEType 0", found, notNullValue());
    assertThat("testFindByMIMEType 1", found.getMIMEType(), equalTo("text/plain"));
    assertFalse("testFindByMIMEType 2", found.isInternal());

    found = BitstreamFormat.findByMIMEType(context, "text/xml");
    assertThat("testFindByMIMEType 3", found, notNullValue());
    assertThat("testFindByMIMEType 4", found.getMIMEType(), equalTo("text/xml"));
    assertFalse("testFindByMIMEType 5", found.isInternal());
  }
  /** Test of findByShortDescription method, of class BitstreamFormat. */
  @Test
  public void testFindByShortDescription() throws SQLException {
    BitstreamFormat found = BitstreamFormat.findByShortDescription(context, "Adobe PDF");
    assertThat("testFindByShortDescription 0", found, notNullValue());
    assertThat("testFindByShortDescription 1", found.getShortDescription(), equalTo("Adobe PDF"));
    assertFalse("testFindByShortDescription 2", found.isInternal());

    found = BitstreamFormat.findByShortDescription(context, "XML");
    assertThat("testFindByShortDescription 3", found, notNullValue());
    assertThat("testFindByShortDescription 4", found.getShortDescription(), equalTo("XML"));
    assertFalse("testFindByShortDescription 5", found.isInternal());
  }
  /** Test of isInternal method, of class BitstreamFormat. */
  @Test
  public void testIsInternal() throws SQLException {
    assertThat("testIsInternal 0", bf.isInternal(), equalTo(false));

    BitstreamFormat found = BitstreamFormat.findByShortDescription(context, "License");
    assertThat("testIsInternal 1", found.isInternal(), equalTo(true));

    found = BitstreamFormat.findByShortDescription(context, "CC License");
    assertThat("testIsInternal 2", found.isInternal(), equalTo(true));

    assertThat("testIsInternal 3", bunknown.isInternal(), equalTo(false));
  }
  /** Test of create method, of class BitstreamFormat. */
  @Test(expected = AuthorizeException.class)
  public void testCreateNotAdmin() throws SQLException, AuthorizeException {
    new NonStrictExpectations() {
      AuthorizeManager authManager;

      {
        AuthorizeManager.isAdmin((Context) any);
        result = false;
      }
    };

    BitstreamFormat found = BitstreamFormat.create(context);
    fail("Exception should have been thrown");
  }
Beispiel #23
0
  /**
   * Each submission step must define its own information to be reviewed during the final
   * Review/Verify Step in the submission process.
   *
   * <p>The information to review should be tacked onto the passed in List object.
   *
   * <p>NOTE: To remain consistent across all Steps, you should first add a sub-List object (with
   * this step's name as the heading), by using a call to reviewList.addList(). This sublist is the
   * list you return from this method!
   *
   * @param reviewList The List to which all reviewable information should be added
   * @return The new sub-List object created by this step, which contains all the reviewable
   *     information. If this step has nothing to review, then return null!
   */
  public List addReviewSection(List reviewList)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // Create a new list section for this step (and set its heading)
    List uploadSection = reviewList.addList("submit-review-" + this.stepAndPage, List.TYPE_FORM);
    uploadSection.setHead(T_head);

    // Review all uploaded files
    Item item = submission.getItem();
    Bundle[] bundles = item.getBundles("ORIGINAL");
    Bitstream[] bitstreams = new Bitstream[0];
    if (bundles.length > 0) {
      bitstreams = bundles[0].getBitstreams();
    }

    for (Bitstream bitstream : bitstreams) {
      BitstreamFormat bitstreamFormat = bitstream.getFormat();

      String name = bitstream.getName();
      String url = makeBitstreamLink(item, bitstream);
      String format = bitstreamFormat.getShortDescription();
      Message support = ReviewStep.T_unknown;
      if (bitstreamFormat.getSupportLevel() == BitstreamFormat.KNOWN) {
        support = T_known;
      } else if (bitstreamFormat.getSupportLevel() == BitstreamFormat.SUPPORTED) {
        support = T_supported;
      }

      org.dspace.app.xmlui.wing.element.Item file = uploadSection.addItem();
      file.addXref(url, name);
      file.addContent(" - " + format + " ");
      file.addContent(support);
    }

    // return this new "upload" section
    return uploadSection;
  }
  /** Test of delete method, of class BitstreamFormat. */
  @Test(expected = IllegalArgumentException.class)
  public void testDeleteUnknown() throws SQLException, AuthorizeException {

    new NonStrictExpectations() {
      AuthorizeManager authManager;

      {
        AuthorizeManager.isAdmin((Context) any);
        result = true;
      }
    };

    bunknown.delete();
    fail("Exception should have been thrown");
  }
  /** Test of delete method, of class BitstreamFormat. */
  @Test(expected = AuthorizeException.class)
  public void testDeleteNotAdmin() throws SQLException, AuthorizeException {

    new NonStrictExpectations() {
      AuthorizeManager authManager;

      {
        AuthorizeManager.isAdmin((Context) any);
        result = false;
      }
    };

    bf.delete();
    fail("Exception should have been thrown");
  }
  /** Test of find method, of class BitstreamFormat. */
  @Test
  public void testFind() throws SQLException {
    BitstreamFormat found = BitstreamFormat.find(context, 1);
    assertThat("testFind 0", found, notNullValue());
    assertThat("testFind 1", found.getShortDescription(), equalTo("Unknown"));

    found = BitstreamFormat.find(context, 2);
    assertThat("testFind 2", found, notNullValue());
    assertThat("testFind 3", found.getShortDescription(), equalTo("License"));
    assertTrue("testFind 4", found.isInternal());
  }
  /** Test of setExtensions method, of class BitstreamFormat. */
  @Test
  public void setExtensions(String[] exts) {
    assertThat("setExtensions 0", bf.getExtensions()[0], equalTo("xml"));

    bf.setExtensions(new String[] {"1", "2", "3"});
    assertThat("setExtensions 1", bf.getExtensions(), notNullValue());
    assertTrue("setExtensions 2", bf.getExtensions().length == 3);
    assertThat("setExtensions 3", bf.getExtensions()[0], equalTo("1"));
    assertThat("setExtensions 4", bf.getExtensions()[1], equalTo("2"));
    assertThat("setExtensions 5", bf.getExtensions()[2], equalTo("3"));

    bf.setExtensions(new String[0]);
    assertThat("setExtensions 6", bf.getExtensions(), notNullValue());
    assertTrue("setExtensions 7", bf.getExtensions().length == 0);
  }
  /** Test of getSupportLevel method, of class BitstreamFormat. */
  @Test
  public void testGetSupportLevel() throws SQLException {

    assertTrue("testGetSupportLevel 0", bf.getSupportLevel() >= 0);
    assertTrue("testGetSupportLevel 1", bf.getSupportLevel() <= 2);

    assertTrue("testGetSupportLevel 2", bunknown.getSupportLevel() >= 0);
    assertTrue("testGetSupportLevel 3", bunknown.getSupportLevel() <= 2);

    BitstreamFormat[] found = BitstreamFormat.findAll(context);
    int i = 0;
    for (BitstreamFormat b : found) {
      i++;
      assertTrue(
          "testGetSupportLevel " + i + " (" + b.getMIMEType() + ")", b.getSupportLevel() >= 0);
      i++;
      assertTrue(
          "testGetSupportLevel " + i + " (" + b.getMIMEType() + ")", b.getSupportLevel() <= 2);
    }
  }
 /** Test of setSupportLevel method, of class BitstreamFormat. */
 @Test
 public void testSetSupportLevelValidValues() {
   bf.setSupportLevel(BitstreamFormat.UNKNOWN);
   assertThat(
       "testSetSupportLevelValidValues 0", bf.getSupportLevel(), equalTo(BitstreamFormat.UNKNOWN));
   bf.setSupportLevel(BitstreamFormat.KNOWN);
   assertThat(
       "testSetSupportLevelValidValues 1", bf.getSupportLevel(), equalTo(BitstreamFormat.KNOWN));
   bf.setSupportLevel(BitstreamFormat.SUPPORTED);
   assertThat(
       "testSetSupportLevelValidValues 2",
       bf.getSupportLevel(),
       equalTo(BitstreamFormat.SUPPORTED));
 }
Beispiel #30
0
  /**
   * Store a copy of the license a user granted in the item.
   *
   * @param context the dspace context
   * @param item the item object of the license
   * @param licenseText the license the user granted
   * @throws SQLException
   * @throws IOException
   * @throws AuthorizeException
   */
  public static void grantLicense(Context context, Item item, String licenseText)
      throws SQLException, IOException, AuthorizeException {
    // Put together text to store
    // String licenseText = "License granted by " + eperson.getFullName()
    // + " (" + eperson.getEmail() + ") on "
    // + DCDate.getCurrent().toString() + " (GMT):\n\n" + license;

    // Store text as a bitstream
    byte[] licenseBytes = licenseText.getBytes();
    ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes);
    Bitstream b = item.createSingleBitstream(bais, "LICENSE");

    // Now set the format and name of the bitstream
    b.setName("license.txt");
    b.setSource("Written by org.dspace.content.LicenseUtils");

    // Find the License format
    BitstreamFormat bf = BitstreamFormat.findByShortDescription(context, "License");
    b.setFormat(bf);

    b.update();
  }