Package org.purl.sword.base

Examples of org.purl.sword.base.DepositResponse


     
      // prep and execute the deposit
      SWORDService service = new SWORDService(sc);
      service.setVerbose(deposit.isVerbose());
      DepositManager dm = new DepositManager(service);
      DepositResponse response = dm.deposit(deposit);
     
      // if something hasn't killed it already (allowed), then complete the transaction
      sc.commit();
     
      return response;
View Full Code Here


    if (handle == null || "".equals(handle))
    {
      state = Deposit.ACCEPTED;
    }
   
    DepositResponse response = new DepositResponse(state);
    response.setLocation(result.getMediaLink());

    DSpaceATOMEntry dsatom = null;
    if (result.getItem() != null)
    {
      swordService.message("Initialising ATOM entry generator for an Item");
      dsatom = new ItemEntryGenerator(swordService);
    }
    else if (result.getBitstream() != null)
    {
      swordService.message("Initialising ATOM entry generator for a Bitstream");
      dsatom = new BitstreamEntryGenerator(swordService);
    }
    if (dsatom == null)
    {
      log.error("The deposit failed, see exceptions for explanation");
      throw new DSpaceSWORDException("Result of deposit did not yield an Item or a Bitstream");
    }
    SWORDEntry entry = dsatom.getSWORDEntry(result, deposit);

    // if this was a no-op, we need to remove the files we just
    // deposited, and abort the transaction
    if (deposit.isNoOp())
    {
      dep.undoDeposit(result);
      swordService.message("NoOp Requested: Removed all traces of submission");
    }
   
    entry.setNoOp(deposit.isNoOp());

    Date finish = new Date();
    long delta = finish.getTime() - start.getTime();
    swordService.message("Total time for deposit processing: " + delta + " ms");
    entry.setVerboseDescription(swordService.getVerboseDescription().toString());

    response.setEntry(entry);
   
    return response;
  }
View Full Code Here

   
    // Handle the deposit
    if (!deposit.isNoOp()) {
      counter++;
    }
    DepositResponse dr = new DepositResponse(Deposit.CREATED);
    SWORDEntry se = new SWORDEntry();
   
    Title t = new Title();
    t.setContent("DummyServer Deposit: #" + counter);
    se.setTitle(t);
   
    se.addCategory("Category");
   
    if (deposit.getSlug() != null) {
      se.setId(deposit.getSlug() + " - ID: " + counter);
    } else {
      se.setId("ID: " + counter);
    }
    
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    TimeZone utc = TimeZone.getTimeZone("UTC");
    sdf.setTimeZone (utc);
    String milliFormat = sdf.format(new Date());
    se.setUpdated(milliFormat);
     
      Summary s = new Summary();
    s.setContent(filenames.toString());
    se.setSummary(s);
    Author a = new Author();
    if (username != null) {
      a.setName(username);
    } else {
      a.setName("unknown");
    }
    se.addAuthors(a);
   
    Link em = new Link();
    em.setRel("edit-media");
    em.setHref("http://www.myrepository.ac.uk/sdl/workflow/my deposit");
    se.addLink(em);
   
    Link e = new Link();
    e.setRel("edit");
    e.setHref("http://www.myrepository.ac.uk/sdl/workflow/my deposit.atom");
    se.addLink(e);
   
    if (deposit.getOnBehalfOf() != null) {
      Contributor c = new Contributor();
      c.setName(deposit.getOnBehalfOf());
      c.setEmail(deposit.getOnBehalfOf() + "@myrepository.ac.uk");
      se.addContributor(c);
    }
   
    Generator generator = new Generator();
    generator.setContent("Stuart's Dummy SWORD Server");
    generator.setUri("http://dummy-sword-server.example.com/");
    generator.setVersion("1.3");
    se.setGenerator(generator);
   
    Content content = new Content();
    try {
      content.setType("application/zip");
    } catch (InvalidMediaTypeException ex) {
      ex.printStackTrace();
    }
    content.setSource("http://www.myrepository.ac.uk/sdl/uploads/upload-" + counter + ".zip");
    se.setContent(content);
   
    se.setTreatment("Short back and sides");
   
    if (deposit.isVerbose()) {
      se.setVerboseDescription("I've done a lot of hard work to get this far!");
    }
   
    se.setNoOp(deposit.isNoOp());
   
    dr.setEntry(se);
   
    dr.setLocation("http://www.myrepository.ac.uk/atom/" + counter);
   
    return dr;
  }
View Full Code Here

        if ((cl != null) && (!cl.equals(""))) {
          d.setContentLength(Integer.parseInt(cl));
        }

        // Get the DepositResponse
        DepositResponse dr = myRepository.doDeposit(d);
       
        // Echo back the user agent
        if (request.getHeader(HttpHeaders.USER_AGENT.toString()) != null) {
          dr.getEntry().setUserAgent(request.getHeader(HttpHeaders.USER_AGENT.toString()));
        }
       
        // Echo back the packaging format
        if (request.getHeader(HttpHeaders.X_PACKAGING.toString()) != null) {
          dr.getEntry().setPackaging(request.getHeader(HttpHeaders.X_PACKAGING.toString()));
        }
       
        // Print out the Deposit Response
        response.setStatus(dr.getHttpResponse());
        if ((dr.getLocation() != null) && (!dr.getLocation().equals("")))
        {
          response.setHeader("Location", dr.getLocation());
        }
        response.setContentType("application/atom+xml; charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.write(dr.marshall());
        out.flush();
      }
    } catch (SWORDAuthenticationException sae) {
      // Ask for credentials again
      if (authN.equals("Basic")) {
View Full Code Here

     *
     */
    public String sendMessage() throws SWORDClientException, HttpException
    {
        message.setFilepath(filename);
        DepositResponse resp = client.postFile(message);
        Status status = client.getStatus();

    if ((status.getCode() == 201) || (status.getCode() == 202))
        {
      SWORDEntry se = resp.getEntry();
            return se.getId();
        }
        else
        {
            String error = status.getCode() + " " + status.getMessage() + " - " + resp.getEntry().getSummary().getContent();
      log.info("Error depositing Sword package : " + error);
            throw new HttpException(error);
        }

    }
View Full Code Here

        if ((cl != null) && (!cl.equals(""))) {
          d.setContentLength(Integer.parseInt(cl));
        }

        // Get the DepositResponse
        DepositResponse dr = myRepository.doDeposit(d);
       
        // Echo back the user agent
        if (request.getHeader(HttpHeaders.USER_AGENT.toString()) != null) {
          dr.getEntry().setUserAgent(request.getHeader(HttpHeaders.USER_AGENT.toString()));
        }
       
        // Echo back the packaging format
        if (request.getHeader(HttpHeaders.X_PACKAGING.toString()) != null) {
          dr.getEntry().setPackaging(request.getHeader(HttpHeaders.X_PACKAGING.toString()));
        }
       
        // Print out the Deposit Response
        response.setStatus(dr.getHttpResponse());
        if ((dr.getLocation() != null) && (!dr.getLocation().equals("")))
        {
          response.setHeader("Location", dr.getLocation());
        }
        response.setContentType("application/atom+xml; charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.write(dr.marshall());
        out.flush();
      }
    } catch (SWORDAuthenticationException sae) {
      // Ask for credentials again
      if (authN.equals("Basic")) {
View Full Code Here

   
    // Handle the deposit
    if (!deposit.isNoOp()) {
      counter++;
    }
    DepositResponse dr = new DepositResponse(Deposit.CREATED);
    SWORDEntry se = new SWORDEntry();
   
    Title t = new Title();
    t.setContent("DummyServer Deposit: #" + counter);
    se.setTitle(t);
   
    se.addCategory("Category");
   
    if (deposit.getSlug() != null) {
      se.setId(deposit.getSlug() + " - ID: " + counter);
    } else {
      se.setId("ID: " + counter);
    }
    
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    TimeZone utc = TimeZone.getTimeZone("UTC");
    sdf.setTimeZone (utc);
    String milliFormat = sdf.format(new Date());
    se.setUpdated(milliFormat);
     
      Summary s = new Summary();
    s.setContent(filenames.toString());
    se.setSummary(s);
    Author a = new Author();
    if (username != null) {
      a.setName(username);
    } else {
      a.setName("unknown");
    }
    se.addAuthors(a);
   
    Link em = new Link();
    em.setRel("edit-media");
    em.setHref("http://www.myrepository.ac.uk/sdl/workflow/my deposit");
    se.addLink(em);
   
    Link e = new Link();
    e.setRel("edit");
    e.setHref("http://www.myrepository.ac.uk/sdl/workflow/my deposit.atom");
    se.addLink(e);
   
    if (deposit.getOnBehalfOf() != null) {
      Contributor c = new Contributor();
      c.setName(deposit.getOnBehalfOf());
      c.setEmail(deposit.getOnBehalfOf() + "@myrepository.ac.uk");
      se.addContributor(c);
    }
   
    Generator generator = new Generator();
    generator.setContent("Stuart's Dummy SWORD Server");
    generator.setUri("http://dummy-sword-server.example.com/");
    generator.setVersion("1.3");
    se.setGenerator(generator);
   
    Content content = new Content();
    try {
      content.setType("application/zip");
    } catch (InvalidMediaTypeException ex) {
      ex.printStackTrace();
    }
    content.setSource("http://www.myrepository.ac.uk/sdl/uploads/upload-" + counter + ".zip");
    se.setContent(content);
   
    se.setTreatment("Short back and sides");
   
    if (deposit.isVerbose()) {
      se.setVerboseDescription("I've done a lot of hard work to get this far!");
    }
   
    se.setNoOp(deposit.isNoOp());
   
    dr.setEntry(se);
   
    dr.setLocation("http://www.myrepository.ac.uk/atom/" + counter);
   
    return dr;
  }
View Full Code Here

    if (handle == null || "".equals(handle))
    {
      state = Deposit.ACCEPTED;
    }
   
    DepositResponse response = new DepositResponse(state);
    response.setLocation(result.getMediaLink());

    DSpaceATOMEntry dsatom = null;
    if (result.getItem() != null)
    {
      swordService.message("Initialising ATOM entry generator for an Item");
      dsatom = new ItemEntryGenerator(swordService);
    }
    else if (result.getBitstream() != null)
    {
      swordService.message("Initialising ATOM entry generator for a Bitstream");
      dsatom = new BitstreamEntryGenerator(swordService);
    }
    if (dsatom == null)
    {
      log.error("The deposit failed, see exceptions for explanation");
      throw new DSpaceSWORDException("Result of deposit did not yield an Item or a Bitstream");
    }
    SWORDEntry entry = dsatom.getSWORDEntry(result, deposit);

    // if this was a no-op, we need to remove the files we just
    // deposited, and abort the transaction
    if (deposit.isNoOp())
    {
      dep.undoDeposit(result);
      swordService.message("NoOp Requested: Removed all traces of submission");
    }
   
    entry.setNoOp(deposit.isNoOp());

    Date finish = new Date();
    long delta = finish.getTime() - start.getTime();
    swordService.message("Total time for deposit processing: " + delta + " ms");
    entry.setVerboseDescription(swordService.getVerboseDescription().toString());

    response.setEntry(entry);
   
    return response;
  }
View Full Code Here

     
      // prep and execute the deposit
      SWORDService service = new SWORDService(sc);
      service.setVerbose(deposit.isVerbose());
      DepositManager dm = new DepositManager(service);
      DepositResponse response = dm.deposit(deposit);
     
      // if something hasn't killed it already (allowed), then complete the transaction
      sc.commit();
     
      return response;
View Full Code Here

   *                                 post response.
   */
  protected void processPost(PostMessage message)
  throws SWORDClientException
  {
    DepositResponse response = client.postFile(message);

    System.out.println("The status is: " + client.getStatus());
   
    if( response != null)
    {
      log.debug("message is: " + response.marshall());
     
      // iterate over the data and output it
      SWORDEntry entry = response.getEntry();
     

      System.out.println("Id: " + entry.getId());
      Title title = entry.getTitle();
      if( title != null )
View Full Code Here

TOP

Related Classes of org.purl.sword.base.DepositResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.