Package org.dspace.core

Examples of org.dspace.core.Context


    // -- the on-behalf-of user is authorised to READ
    // -- the on-behalf-of user is null
    try
    {
      Community[] comms = community.getSubcommunities();
      Context context = swordContext.getContext();
      List<Community> allowed = new ArrayList<Community>();

      for (int i = 0; i < comms.length; i++)
      {
        boolean authAllowed = false;
View Full Code Here


    // -- the on-behalf-of user is null

    try
    {
      // get the context of the authenticated user
      Context authContext = swordContext.getAuthenticatorContext();

      // short cut by obtaining the collections to which the authenticated user can submit
      org.dspace.content.Collection[] cols = org.dspace.content.Collection.findAuthorized(authContext, community, Constants.ADD);
      List<org.dspace.content.Collection> allowed = new ArrayList<org.dspace.content.Collection>();
View Full Code Here

     * @throws SQLException
     */
    public static void main(String[] args) throws SQLException, IOException
    {

      Context context = new Context();
        context.setIgnoreAuthorization(true);
       
        String usage = "org.dspace.search.DSIndexer [-cbhof[r <item handle>]] or nothing to update/clean an existing index.";
        Options options = new Options();
        HelpFormatter formatter = new HelpFormatter();
        CommandLine line = null;
View Full Code Here

   */
  public DepositResult doDeposit(Deposit deposit)
      throws SWORDErrorException, DSpaceSWORDException
  {
    // get the things out of the service that we need
    Context context = swordService.getContext();
    SWORDConfiguration swordConfig = swordService.getSwordConfig();
    SWORDUrlManager urlManager = swordService.getUrlManager();

    // FIXME: the spec is unclear what to do in this situation.  I'm going
    // the throw a 415 (ERROR_CONTENT) until further notice
    //
    // determine if this is an acceptable file format
    if (!swordConfig.isAcceptableContentType(context, deposit.getContentType(), collection))
    {
      log.error("Unacceptable content type detected: " + deposit.getContentType() + " for collection " + collection.getID());
      throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
          "Unacceptable content type in deposit request: " + deposit.getContentType());
    }

    // determine if this is an acceptable packaging type for the deposit
    // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
    if (!swordConfig.isSupportedMediaType(deposit.getPackaging(), this.collection))
    {
      log.error("Unacceptable packaging type detected: " + deposit.getPackaging() + "for collection" + collection.getID());
      throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
          "Unacceptable packaging type in deposit request: " + deposit.getPackaging());
    }

    String tempDir = swordConfig.getTempDir();
    String tempFile = tempDir + "/" + swordService.getTempFilename();
    log.debug("Storing temporary file at " + tempFile);

    if (swordConfig.isKeepOriginal())
    {
      try
      {
        swordService.message("DSpace will store an original copy of the deposit, " +
            "as well as ingesting the item into the archive");

        // first, store the temp file
        InputStream is = deposit.getFile();
        FileOutputStream fos = new FileOutputStream(tempFile);
        Utils.copy(is, fos);
        fos.close();
        is.close();

        // now create an input stream from that temp file to ingest
        InputStream fis = new FileInputStream(tempFile);
        deposit.setFile(fis);
      }
      catch (FileNotFoundException e)
      {
        log.error("caught exception: ", e);
        throw new DSpaceSWORDException(e);
      }
      catch (IOException e)
      {
        log.error("caught exception: ", e);
        throw new DSpaceSWORDException(e);
      }
    }

    // Obtain the relevant ingester from the factory
    SWORDIngester si = SWORDIngesterFactory.getInstance(context, deposit, collection);
    swordService.message("Loaded ingester: " + si.getClass().getName());

    // do the deposit
    DepositResult result = si.ingest(swordService, deposit, collection);
    swordService.message("Archive ingest completed successfully");

    // if there's an item availalble, and we want to keep the original
    // then do that
    try
    {
      if (swordConfig.isKeepOriginal())
      {
        // in order to be allowed to add the file back to the item, we need to ignore authorisations
        // for a moment
        boolean ignoreAuth = context.ignoreAuthorization();
        context.setIgnoreAuthorization(true);

        String bundleName = ConfigurationManager.getProperty("sword.bundle.name");
        if (bundleName == null || "".equals(bundleName))
        {
          bundleName = "SWORD";
        }
        Item item = result.getItem();
        Bundle[] bundles = item.getBundles(bundleName);
        Bundle swordBundle = null;
        if (bundles.length > 0)
        {
          swordBundle = bundles[0];
        }
        if (swordBundle == null)
        {
          swordBundle = item.createBundle(bundleName);
        }

        String fn = swordService.getFilename(context, deposit, true);

        FileInputStream fis = new FileInputStream(tempFile);
        Bitstream bitstream = swordBundle.createBitstream(fis);
        bitstream.setName(fn);
        bitstream.setDescription("SWORD deposit package");

        BitstreamFormat bf = BitstreamFormat.findByMIMEType(context, deposit.getContentType());
        if (bf != null)
        {
          bitstream.setFormat(bf);
        }

        bitstream.update();
        swordBundle.update();
        item.update();

        swordService.message("Original package stored as " + fn + ", in item bundle " + swordBundle);

        // now reset the context ignore authorisation
        context.setIgnoreAuthorization(ignoreAuth);

        // set the media link for the created item
        result.setMediaLink(urlManager.getMediaLink(bitstream));
      }
      else
View Full Code Here

     */
    public static void main(String [] argv)
        throws Exception, SQLException
    {
        // create context as super user
        Context context = new Context();
        context.setIgnoreAuthorization(true);
       
        String myFormat = null;
        String myInput = null;
        String myOutput = null;
        String myMap = null;
View Full Code Here

        {
            sitemapsOrg = new SitemapsOrgGenerator(outputDir, sitemapStem
                    + "?map=", null);
        }

        Context c = new Context();

        Community[] comms = Community.findAll(c);

        for (int i = 0; i < comms.length; i++)
        {
            String url = handleURLStem + comms[i].getHandle();

            if (makeHTMLMap)
                html.addURL(url, null);
            if (makeSitemapOrg)
                sitemapsOrg.addURL(url, null);
        }

        Collection[] colls = Collection.findAll(c);

        for (int i = 0; i < colls.length; i++)
        {
            String url = handleURLStem + colls[i].getHandle();

            if (makeHTMLMap)
                html.addURL(url, null);
            if (makeSitemapOrg)
                sitemapsOrg.addURL(url, null);
        }

        ItemIterator allItems = Item.findAll(c);
        try
        {
            int itemCount = 0;

            while (allItems.hasNext())
            {
                Item i = allItems.next();
                String url = handleURLStem + i.getHandle();
                Date lastMod = i.getLastModified();

                if (makeHTMLMap)
                    html.addURL(url, lastMod);
                if (makeSitemapOrg)
                    sitemapsOrg.addURL(url, lastMod);
                i.decache();

                itemCount++;
            }

            if (makeHTMLMap)
            {
                int files = html.finish();
                log.info(LogManager.getHeader(c, "write_sitemap",
                        "type=html,num_files=" + files + ",communities="
                                + comms.length + ",collections=" + colls.length
                                + ",items=" + itemCount));
            }

            if (makeSitemapOrg)
            {
                int files = sitemapsOrg.finish();
                log.info(LogManager.getHeader(c, "write_sitemap",
                        "type=html,num_files=" + files + ",communities="
                                + comms.length + ",collections=" + colls.length
                                + ",items=" + itemCount));
            }
        }
        finally
        {
            if (allItems != null)
                allItems.close();
        }
       
        c.abort();
    }
View Full Code Here

        System.out.println("Command line query: " + query);
        System.out.println("Only reporting default-sized results list");

        try
        {
            Context c = new Context();

            QueryArgs args = new QueryArgs();
            args.setQuery(query);

            QueryResults results = doQuery(c, args);
View Full Code Here

     */
    private synchronized void init()
    {
        if (init == Boolean.FALSE)
        {
            Context context = null;
            int dsoType = -1;

            int id = -1;
            try
            {
                context = new Context();
                DSpaceObject dso = HandleManager.resolveToObject(context, handle);
                id = dso.getID();
                dsoType = dso.getType();
                context.abort();

            }
            catch (SQLException e)
            {
                LOG.error("init error " + e.getMessage(), e);
                throw new RuntimeException("init error" + e.getMessage(), e);

            }
            finally
            {
                // Abort the context if it's still valid
                if ((context != null) && context.isValid())
                {
                    context.abort();
                }
            }

            List ids = new ArrayList();

View Full Code Here

            PackageParameters pparams = new PackageParameters();
            pparams.put("manifestOnly", "true");

            // "pipe" the output into a parser to create JDOM document.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Context context = new Context();
            dip.disseminate(context, item, pparams, baos);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

            try
            {
View Full Code Here

     */
    public static void main(String[] args) throws SQLException,
            AuthorizeException, IOException
    {

        Context ctx = new Context();
        ctx.setIgnoreAuthorization(true);
        ItemIterator iter = Item.findAll(ctx);

        Properties props = new Properties();

        File processed = new File("license.processed");
View Full Code Here

TOP

Related Classes of org.dspace.core.Context

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.