Package org.dspace.core

Examples of org.dspace.core.Context


    {
        // first, start the processing clock
        startTime = new GregorianCalendar();
       
        // create context as super user
        Context context = new Context();
        context.setIgnoreAuthorization(true);
       
        // set up our command line variables
        String myLogDir = null;
        String myFileTemplate = null;
        String myConfigFile = null;
View Full Code Here


   * @throws SWORDAuthenticationException
   */
  public SWORDContext authenticate(ServiceDocumentRequest request)
      throws SWORDException, SWORDErrorException, SWORDAuthenticationException
  {
    Context context = this.constructContext(request.getIPAddress());
    SWORDContext sc = null;
    try
        {
            sc = this.authenticate(context, request);
        }
        catch (SWORDException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDErrorException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDAuthenticationException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (RuntimeException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
    return sc;
  }
View Full Code Here

   * @throws SWORDAuthenticationException
   */
  public SWORDContext authenticate(AtomDocumentRequest request)
      throws SWORDException, SWORDErrorException, SWORDAuthenticationException
  {
    Context context = this.constructContext(request.getIPAddress());
    SWORDContext sc = null;
    try
        {
            sc = this.authenticate(context, request);
        }
        catch (SWORDException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDErrorException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDAuthenticationException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (RuntimeException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        return sc;
    }
View Full Code Here

    private static Properties dcToMODS;

    public static void main(String[] args) throws Exception
    {
        Context context = new Context();

        init(context);

        // create an options object and populate it
        CommandLineParser parser = new PosixParser();

        Options options = new Options();

        options.addOption("c", "collection", true,
                "Handle of collection to export");
        options.addOption("i", "item", true, "Handle of item to export");
        options.addOption("a", "all", false, "Export all items in the archive");
        options.addOption("d", "destination", true, "Destination directory");
        options.addOption("h", "help", false, "Help");

        CommandLine line = parser.parse(options, args);

        if (line.hasOption('h'))
        {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("metsexport", options);
            System.out
                    .println("\nExport a collection:  metsexport -c hdl:123.456/789");
            System.out
                    .println("Export an item:       metsexport -i hdl:123.456/890");
            System.out.println("Export everything:    metsexport -a");

            System.exit(0);
        }

        String dest = "";

        if (line.hasOption('d'))
        {
            dest = line.getOptionValue('d');

            // Make sure it ends with a file separator
            if (!dest.endsWith(File.separator))
            {
                dest = dest + File.separator;
            }
        }

        if (line.hasOption('i'))
        {
            String handle = getHandleArg(line.getOptionValue('i'));

            // Exporting a single item
            DSpaceObject o = HandleManager.resolveToObject(context, handle);

            if ((o != null) && o instanceof Item)
            {
                writeAIP(context, (Item) o, dest);
                System.exit(0);
            }
            else
            {
                System.err.println(line.getOptionValue('i')
                        + " is not a valid item Handle");
                System.exit(1);
            }
        }

        ItemIterator items = null;
        try
        {
            if (line.hasOption('c'))
            {
                String handle = getHandleArg(line.getOptionValue('c'));

                // Exporting a collection's worth of items
                DSpaceObject o = HandleManager.resolveToObject(context, handle);

                if ((o != null) && o instanceof Collection)
                {
                    items = ((Collection) o).getItems();
                }
                else
                {
                    System.err.println(line.getOptionValue('c')
                            + " is not a valid collection Handle");
                    System.exit(1);
                }
            }

            if (line.hasOption('a'))
            {
                items = Item.findAll(context);
            }

            if (items == null)
            {
                System.err.println("Nothing to export specified!");
                System.exit(1);
            }

            while (items.hasNext())
            {
                writeAIP(context, items.next(), dest);
            }
        }
        finally
        {
            if (items != null)
                items.close();
        }
       
        context.abort();
        System.exit(0);
    }
View Full Code Here

   * @throws SWORDAuthenticationException
   */
  public SWORDContext authenticate(Deposit deposit)
      throws SWORDException, SWORDErrorException, SWORDAuthenticationException
  {
    Context context = this.constructContext(deposit.getIPAddress());
    SWORDContext sc = null;
    try
    {
        sc = this.authenticate(context, deposit);
    }
        catch (SWORDException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDErrorException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (SWORDAuthenticationException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        catch (RuntimeException e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
            throw e;
        }
        return sc;
  }
View Full Code Here

          }

          if (epObo != null)
          {
            sc.setOnBehalfOf(epObo);
            Context oboContext = this.constructContext(ip);
            oboContext.setCurrentUser(epObo);
                    // Set any special groups - invoke the authentication mgr.
                      int[] groupIDs = AuthenticationManager.getSpecialGroups(oboContext, null);

                      for (int i = 0; i < groupIDs.length; i++)
                      {
                          oboContext.setSpecialGroup(groupIDs[i]);
                          log.debug("Adding Special Group id="+String.valueOf(groupIDs[i]));
                      }
            sc.setContext(oboContext);
          }
          else
View Full Code Here

  public boolean isUserAdmin(SWORDContext swordContext)
    throws DSpaceSWORDException
  {
    try
    {
      Context context = swordContext.getContext();
      EPerson authenticated = swordContext.getAuthenticated();
      if (authenticated != null)
      {
        return AuthorizeManager.isAdmin(swordContext.getAuthenticatorContext());
      }
View Full Code Here

   * @throws SQLException
   */
  public boolean isOnBehalfOfAdmin(SWORDContext swordContext)
    throws DSpaceSWORDException
  {
    Context context = swordContext.getContext();
    EPerson onBehalfOf = swordContext.getOnBehalfOf();
    try
    {
      if (onBehalfOf != null)
      {
View Full Code Here

        boolean isTest = false;
        boolean alterProvenance = true;
        String itemField = null;
        String metadataIndexName = null;
       
        Context context = null;
        ItemUpdate iu = new ItemUpdate()

        try
        {      
          CommandLine line = parser.parse(options, argv);
 
          if (line.hasOption('h'))
          {
              HelpFormatter myhelp = new HelpFormatter();
              myhelp.printHelp("ItemUpdate", options);
              pr("");
              pr("Examples:");
              pr("  adding metadata:     ItemUpdate -e jsmith@mit.edu -s sourcedir -a dc.contributor -a dc.subject ");
              pr("  deleting metadata:   ItemUpdate -e jsmith@mit.edu -s sourcedir -d dc.description.other");
              pr("  adding bitstreams:   ItemUpdate -e jsmith@mit.edu -s sourcedir -A -i dc.identifier");
              pr("  deleting bitstreams: ItemUpdate -e jsmith@mit.edu -s sourcedir -D ORIGINAL ");
              pr("");
 
              System.exit(0);
          }
         
          if (line.hasOption('v'))
          {
            verbose = true;
          }

          if (line.hasOption('P'))
          {
            alterProvenance = false;
            pr("Suppressing changes to Provenance field option");
          }

          iu.eperson = line.getOptionValue('e'); // db ID or email
         
          if (!line.hasOption('s')) // item specific changes from archive dir
          {
            pr("Missing source archive option");
            System.exit(1);
          }
          String sourcedir = line.getOptionValue('s');
         
          if (line.hasOption('t'))  //test
          {
            isTest = true;
              pr("**Test Run** - not actually updating items.");
                   
          }
         
          if (line.hasOption('i'))
          {
            itemField = line.getOptionValue('i');         
          }

          if (line.hasOption('d'))
          {
            String[] targetFields = line.getOptionValues('d');
           
            DeleteMetadataAction delMetadataAction = (DeleteMetadataAction) iu.actionMgr.getUpdateAction(DeleteMetadataAction.class);
            delMetadataAction.addTargetFields(targetFields);
           
            //undo is an add
            for (String field : targetFields)
            {
              iu.undoActionList.add(" -a " + field + " ");
            }
           
            pr("Delete metadata for fields: ");
            for (String s : targetFields)
            {
              pr("    " + s);
            }
          }
         
        if (line.hasOption('a'))
        {
          String[] targetFields = line.getOptionValues('a');
         
          AddMetadataAction addMetadataAction = (AddMetadataAction) iu.actionMgr.getUpdateAction(AddMetadataAction.class);
          addMetadataAction.addTargetFields(targetFields);
           
            //undo is a delete followed by an add of a replace record for target fields
            for (String field : targetFields)
            {
              iu.undoActionList.add(" -d " + field + " ");
            }
         
            for (String field : targetFields)
            {
              iu.undoActionList.add(" -a " + field + " ");
            }
         
            pr("Add metadata for fields: ");
            for (String s : targetFields)
            {
              pr("    " + s);
            }
          }
       
          if (line.hasOption('D'))  // undo not supported
          {
            pr("Delete bitstreams ");
           
            String[] filterNames = line.getOptionValues('D');
            if ((filterNames != null) && (filterNames.length > 1))
            {
              pr("Error: Only one filter can be a used at a time.");
              System.exit(1);
            }
           
            String filterName = line.getOptionValue('D');
            pr("Filter argument: " + filterName);
           
            if (filterName == null// indicates using delete_contents files
            {
              DeleteBitstreamsAction delAction = (DeleteBitstreamsAction) iu.actionMgr.getUpdateAction(DeleteBitstreamsAction.class);
              delAction.setAlterProvenance(alterProvenance);
            }
            else
            {
                // check if param is on ALIAS list
              String filterClassname = filterAliases.get(filterName);
             
              if (filterClassname == null)
              {
                filterClassname = filterName;
              }
                           
                BitstreamFilter filter = null;

                try
                {
              Class<?> cfilter = Class.forName(filterClassname);
              pr("BitstreamFilter class to instantiate: " + cfilter.toString());
             
              filter =  (BitstreamFilter) cfilter.newInstance()//unfortunate cast, an erasure consequence
                }
                catch(Exception e)
                {
                  pr("Error:  Failure instantiating bitstream filter class: " + filterClassname);
                  System.exit(1);
                }
               
                String filterPropertiesName = line.getOptionValue('F');
                if (filterPropertiesName != null//not always required
                {
                  try
                  {
                    // TODO try multiple relative locations, e.g. source dir
                    if (!filterPropertiesName.startsWith("/"))
                    {
                      filterPropertiesName = sourcedir + File.separator + filterPropertiesName;
                    }
                   
                    filter.initProperties(filterPropertiesName);
                  }
                  catch(Exception e)
                  {
                    pr("Error:  Failure finding properties file for bitstream filter class: " + filterPropertiesName);
                    System.exit(1);
                  }
                }
               
              DeleteBitstreamsByFilterAction delAction =
                (DeleteBitstreamsByFilterAction) iu.actionMgr.getUpdateAction(DeleteBitstreamsByFilterAction.class);
              delAction.setAlterProvenance(alterProvenance);
              delAction.setBitstreamFilter(filter);
                //undo not supported
            }         
          }

          if (line.hasOption('A'))
          {
            pr("Add bitstreams ");               
            AddBitstreamsAction addAction = (AddBitstreamsAction) iu.actionMgr.getUpdateAction(AddBitstreamsAction.class);
            addAction.setAlterProvenance(alterProvenance);
           
            iu.undoActionList.add(" -D ")// delete_contents file will be written, no arg required           
          }             
                   
          if (!iu.actionMgr.hasActions())
          {
                pr("Error - an action must be specified");
                System.exit(1);
          }
          else 
          {
            pr("Actions to be performed: ");
           
            for (UpdateAction ua : iu.actionMgr)
            {
              pr("    " + ua.getClass().getName());
            }
          }
         
          pr("ItemUpdate - initializing run on " + (new Date()).toString());
                  
          context = new Context()
          iu.setEPerson(context, iu.eperson)
          context.setIgnoreAuthorization(true);
         
        HANDLE_PREFIX = ConfigurationManager.getProperty("handle.canonical.prefix");
        if (HANDLE_PREFIX == null || HANDLE_PREFIX.length() == 0)
        {
          HANDLE_PREFIX = "http://hdl.handle.net/";
        }
                 
          iu.processArchive(context, sourcedir, itemField, metadataIndexName, alterProvenance, isTest);                         

          context.complete()// complete all transactions
          context.setIgnoreAuthorization(false);
        }
        catch (Exception e)
        {
            if (context != null && context.isValid())
            {
                context.abort();
              context.setIgnoreAuthorization(false);
            }
            e.printStackTrace();
            pr(e.toString());
            status = 1;
        }
View Full Code Here

    // -- the on-behalf-of user is authorised to READ
    // -- the on-behalf-of user is null
    try
    {
      // locate all the top level communities
      Context context = swordContext.getContext();
      List<Community> allowed = new ArrayList<Community>();
      Community[] comms = Community.findAllTop(context);
      for (int i = 0; i < comms.length; i++)
      {
        boolean authAllowed = false;
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.