Package org.dspace.core

Examples of org.dspace.core.Context


          usage();
          System.exit(0);
      }
     
        // create a context
        Context context = new Context();
       
        // set the context
        context.setCurrentUser(EPerson.findByEmail(context, eperson));
        // load the XML
        Document document = loadXML(file);
       
        // run the preliminary validation, to be sure that the the XML document
        // is properly structured
        validate(document);
       
        // load the mappings into the member variable hashmaps
        communityMap.put("name", "name");
        communityMap.put("description", "short_description");
        communityMap.put("intro", "introductory_text");
        communityMap.put("copyright", "copyright_text");
        communityMap.put("sidebar", "side_bar_text");
       
        collectionMap.put("name", "name");
        collectionMap.put("description", "short_description");
        collectionMap.put("intro", "introductory_text");
        collectionMap.put("copyright", "copyright_text");
        collectionMap.put("sidebar", "side_bar_text");
        collectionMap.put("license", "license");
        collectionMap.put("provenance", "provenance_description");
       
        // get the top level community list
        NodeList first = XPathAPI.selectNodeList(document, "/import_structure/community");
       
        // run the import starting with the top level communities
        Element[] elements = handleCommunities(context, first, null);
       
        // generate the output
        Element root = xmlOutput.getRootElement();
        for (int i = 0; i < elements.length; i++)
        {
            root.addContent(elements[i]);
        }
       
        // finally write the string into the output file
        try
        {
            BufferedWriter out = new BufferedWriter(new FileWriter(output));
            out.write(new XMLOutputter().outputString(xmlOutput));
            out.close();
        }
        catch (IOException e)
        {
            System.out.println("Unable to write to output file " + output);
            System.exit(0);
        }
       
        context.complete();
    }
View Full Code Here


     * @throws BrowseException
     */
    public IndexBrowse()
      throws SQLException, BrowseException
    {
      this(new Context());
    }
View Full Code Here

   *            Command-line arguments
   */
  public static void main(String[] argv)
    throws SQLException, BrowseException, ParseException
  {
        Context context = new Context();
        context.turnOffAuthorisationSystem();
        IndexBrowse indexer = new IndexBrowse(context);
     
      // create an options object and populate it
      CommandLineParser parser = new PosixParser();
      Options options = new Options();
    
      // these are mutually exclusive, and represent the primary actions
      options.addOption("t", "tables", false, "create the tables only, do not attempt to index.  Mutually exclusive with -f and -i");
      options.addOption("i", "index", false, "actually do the indexing.  Mutually exclusive with -t and -f");
      options.addOption("f", "full", false, "make the tables, and do the indexing.  This forces -x.  Mutually exclusive with -t and -i");
     
      // these options can be specified only with the -f option
      options.addOption("r", "rebuild", false, "should we rebuild all the indices, which removes old index tables and creates new ones.  For use with -f. Mutually exclusive with -d");
      options.addOption("d", "delete", false, "delete all the indices, but don't create new ones.  For use with -f. This is mutually exclusive with -r");
     
      // these options can be specified only with the -t and -f options
      options.addOption("o", "out", true, "[-o <filename>] write the remove and create SQL to the given file. For use with -t and -f")// FIXME: not currently working
      options.addOption("p", "print", false, "write the remove and create SQL to the stdout. For use with -t and -f");
      options.addOption("x", "execute", false, "execute all the remove and create SQL against the database. For use with -t and -f");
      options.addOption("s", "start", true, "[-s <int>] start from this index number and work upward (mostly only useful for debugging). For use with -t and -f");
     
      // this option can be used with any argument
      options.addOption("v", "verbose", false, "print extra information to the stdout.  If used in conjunction with -p, you cannot use the stdout to generate your database structure");
     
      // display the help.  If this is spefified, it trumps all other arguments
      options.addOption("h", "help", false, "show this help documentation.  Overrides all other arguments");
     
      CommandLine line = parser.parse(options, argv);
     
      // display the help
      if (line.hasOption("h"))
      {
        indexer.usage(options);
        return;
      }
     
      if (line.hasOption("v"))
      {
        indexer.setVerbose(true);
      }
     
      if (line.hasOption("i"))
      {
        indexer.createIndex();
        return;
      }
     
      if (line.hasOption("f"))
      {
        if (line.hasOption('r'))
        {
            indexer.setRebuild(true);
        }
        else if (line.hasOption("d"))
        {
          indexer.setDelete(true);
        }
      }
     
      if (line.hasOption("f") || line.hasOption("t"))
      {
        if (line.hasOption("s"))
        {
          indexer.setStart(Integer.parseInt(line.getOptionValue("s")));
        }
        if (line.hasOption("x"))
        {
          indexer.setExecute(true);
        }
        if (line.hasOption("p"))
        {
          indexer.setStdOut(true);
        }
        if (line.hasOption("o"))
        {
          indexer.setFileOut(true);
          indexer.setOutFile(line.getOptionValue("o"));
        }
      }
     
      if (line.hasOption("t"))
      {
        indexer.prepTables();
        return;
      }
     
      if (line.hasOption("f"))
      {
        indexer.setExecute(true);
        indexer.initBrowse();
        return;
      }
     
      indexer.usage(options);
        context.complete();
  }
View Full Code Here

     * @param argv
     *            command-line arguments
     */
    public static void main(String[] argv)
    {
        Context context = null;

        try
        {
            context = new Context();

            // Deal with withdrawn items first.
            // last_modified takes the value of the deletion date
            TableRowIterator tri = DatabaseManager.queryTable(context, "item",
                    "SELECT * FROM item WHERE withdrawal_date IS NOT NULL");

            while (tri.hasNext())
            {
                TableRow row = tri.next();
                DCDate d = new DCDate(row.getStringColumn("withdrawal_date"));
                row.setColumn("last_modified", d.toDate());
                DatabaseManager.update(context, row);
            }
            tri.close();

            // Next, update those items with a date.available
            tri = DatabaseManager.query(context,
                        "SELECT item.item_id, dcvalue.text_value FROM item, dctyperegistry, "+
                        "dcvalue WHERE item.item_id=dcvalue.item_id AND dcvalue.dc_type_id="+
                        "dctyperegistry.dc_type_id AND dctyperegistry.element LIKE 'date' "+
                        "AND dctyperegistry.qualifier LIKE 'available'");

            while (tri.hasNext())
            {
                TableRow resultRow = tri.next();
                DCDate d = new DCDate(resultRow.getStringColumn("text_value"));

                // Can't update the row, have to do a separate query
                TableRow itemRow = DatabaseManager.find(context, "item",
                        resultRow.getIntColumn("item_id"));
                itemRow.setColumn("last_modified", d.toDate());
                DatabaseManager.update(context, itemRow);
            }
            tri.close();

            // Finally, for all items that have no date.available or withdrawal
            // date, set the update time to now!
            DatabaseManager.updateQuery(context,
                        "UPDATE item SET last_modified=now() WHERE last_modified IS NULL");

            context.complete();

            System.out.println("Last modified dates set");

            System.exit(0);
        }
        catch (Exception e)
        {
            System.err.println("Exception occurred:" + e);
            e.printStackTrace();

            if (context != null)
            {
                context.abort();
            }

            System.exit(1);
        }
    }
View Full Code Here

*/
public class Upgrade11To12
{
    public static void main(String[] argv) throws Exception
    {
        Context c = new Context();

        // ve are superuser!
        c.setIgnoreAuthorization(true);

        ItemIterator ii = null;

        // first set owning Collections
        Collection[] collections = Collection.findAll(c);

        System.out.println("Setting item owningCollection fields in database");

        for (int q = 0; q < collections.length; q++)
        {
            ii = collections[q].getItems();

            while (ii.hasNext())
            {
                Item myItem = ii.next();

                // set it if it's not already set
                if (myItem.getOwningCollection() == null)
                {
                    myItem.setOwningCollection(collections[q]);
                    myItem.update();
                    System.out.println("Set owner of item " + myItem.getID()
                            + " to collection " + collections[q].getID());
                }
            }
        }

        // commit pending transactions before continuing
        c.commit();

        // now combine some bundles
        ii = Item.findAll(c);

        while (ii.hasNext())
        {
            boolean skipItem = false;
            Item myItem = ii.next();

            int licenseBundleIndex = -1; // array index of license bundle (we'll
                                         // skip this one often)
            int primaryBundleIndex = -1; // array index of our primary bundle
                                         // (all bitstreams assemble here)

            System.out.println("Processing item #: " + myItem.getID());

            Bundle[] myBundles = myItem.getBundles();

            // look for bundles with multiple bitstreams
            // (if any found, we'll skip this item)
            for (int i = 0; i < myBundles.length; i++)
            {
                // skip if bundle is already named
                if (myBundles[i].getName() != null)
                {
                    System.out
                            .println("Skipping this item - named bundles already found");
                    skipItem = true;

                    break;
                }

                Bitstream[] bitstreams = myBundles[i].getBitstreams();

                // skip this item if we already have bundles combined in this
                // item
                if (bitstreams.length > 1)
                {
                    System.out
                            .println("Skipping this item - compound bundles already found");
                    skipItem = true;

                    break;
                }

                // is this the license? check the format
                BitstreamFormat bf = bitstreams[0].getFormat();

                if (bf.getShortDescription().equals("License"))
                {
                    System.out.println("Found license!");

                    if (licenseBundleIndex == -1)
                    {
                        licenseBundleIndex = i;
                        System.out.println("License bundle set to: " + i);
                    }
                    else
                    {
                        System.out
                                .println("ERROR - multiple license bundles in item - skipping");
                        skipItem = true;

                        break;
                    }
                }
                else
                {
                    // not a license, if primary isn't set yet, set it
                    if (primaryBundleIndex == -1)
                    {
                        primaryBundleIndex = i;
                        System.out.println("Primary bundle set to: " + i);
                    }
                }
            }

            if (!skipItem)
            {
                // name the primary and license bundles
                if (primaryBundleIndex != -1)
                {
                    myBundles[primaryBundleIndex].setName("ORIGINAL");
                    myBundles[primaryBundleIndex].update();
                }

                if (licenseBundleIndex != -1)
                {
                    myBundles[licenseBundleIndex].setName("LICENSE");
                    myBundles[licenseBundleIndex].update();
                }

                for (int i = 0; i < myBundles.length; i++)
                {
                    Bitstream[] bitstreams = myBundles[i].getBitstreams();

                    // now we can safely assume no bundles with multiple
                    // bitstreams
                    if (bitstreams.length > 0)
                    {
                        if ((i != primaryBundleIndex)
                                && (i != licenseBundleIndex))
                        {
                            // only option left is a bitstream to be combined
                            // with primary bundle
                            // and remove now-redundant bundle
                            myBundles[primaryBundleIndex]
                                    .addBitstream(bitstreams[0]); // add to
                                                                  // primary
                            myItem.removeBundle(myBundles[i]); // remove this
                                                               // bundle

                            System.out.println("Bitstream from bundle " + i
                                    + " moved to primary bundle");

                            // flag if HTML bitstream
                            if (bitstreams[0].getFormat().getMIMEType().equals(
                                    "text/html"))
                            {
                                System.out
                                        .println("Set primary bitstream to HTML file in item #"
                                                + myItem.getID()
                                                + " for HTML support.");
                            }
                        }
                    }
                }
            }
        }

        c.complete();
    }
View Full Code Here

   * @param args
   */
  public static void main(String[] args)
    throws ItemCountException, SQLException
  {
        Context context = new Context();
        ItemCounter ic = new ItemCounter(context);
    ic.buildItemCounts();
        context.complete();
  }
View Full Code Here

            outputter.output(dimDoc, System.out);
            dimList = dimDoc.getRootElement().getChildren();
        }

        // Sanity-check the generated DIM, make sure it would load.
        Context context = new Context();
        Iterator di = dimList.iterator();
        while (di.hasNext())
        {
            // skip over comment, text and other trash some XSLs generate..
            Object o = di.next();
View Full Code Here

            System.out
                    .println("ID must be set to either a database ID or a handle (-h for help)");
            System.exit(1);
        }

        Context c = new Context();
        c.setIgnoreAuthorization(true);

        if (myType == Constants.ITEM)
        {
            // first, is myIDString a handle?
            if (myIDString.indexOf('/') != -1)
            {
                myItem = (Item) HandleManager.resolveToObject(c, myIDString);

                if ((myItem == null) || (myItem.getType() != Constants.ITEM))
                {
                    myItem = null;
                }
            }
            else
            {
                myItem = Item.find(c, Integer.parseInt(myIDString));
            }

            if (myItem == null)
            {
                System.out
                        .println("Error, item cannot be found: " + myIDString);
            }
        }
        else
        {
            if (myIDString.indexOf('/') != -1)
            {
                // has a / must be a handle
                mycollection = (Collection) HandleManager.resolveToObject(c,
                        myIDString);

                // ensure it's a collection
                if ((mycollection == null)
                        || (mycollection.getType() != Constants.COLLECTION))
                {
                    mycollection = null;
                }
            }
            else if (myIDString != null)
            {
                mycollection = Collection.find(c, Integer.parseInt(myIDString));
            }

            if (mycollection == null)
            {
                System.out.println("Error, collection cannot be found: "
                        + myIDString);
                System.exit(1);
            }
        }

        if (zip)
        {
            ItemIterator items;
            if (myItem != null)
            {
                items = new ItemIterator(c, new ArrayList(myItem.getID()));
            }
            else
            {
                System.out.println("Exporting from collection: " + myIDString);
                items = mycollection.getItems();
            }
            exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate);
        }
        else
        {
            if (myItem != null)
            {
                // it's only a single item
                exportItem(c, myItem, destDirName, seqStart, migrate);
            }
            else
            {
                System.out.println("Exporting from collection: " + myIDString);

                // it's a collection, so do a bunch of items
                ItemIterator i = mycollection.getItems();
                try
                {
                    exportItem(c, i, destDirName, seqStart, migrate);
                }
                finally
                {
                    if (i != null)
                        i.close();
                }
            }
        }

        c.complete();
    }
View Full Code Here

        return null;
      }
     
        try
        {
          Context context = ContextUtil.obtainContext(objectModel);
            DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
           
            if (dso == null)
              return null;
           
View Full Code Here

        {
            Thread go = new Thread()
            {
                public void run()
                {
                    Context context = null;
                    ItemIterator iitems = null;
                    try
                    {
                        // create a new dspace context
                        context = new Context();
                        // ignore auths
                        context.setIgnoreAuthorization(true);
                        iitems = new ItemIterator(context, items);

                        String fileName = assembleFileName("item", eperson,
                                new Date());
                        String workDir = getExportWorkDirectory()
                                + System.getProperty("file.separator")
                                + fileName;
                        String downloadDir = getExportDownloadDirectory(eperson
                                .getID());

                        File wkDir = new File(workDir);
                        if (!wkDir.exists())
                        {
                            wkDir.mkdirs();
                        }

                        File dnDir = new File(downloadDir);
                        if (!dnDir.exists())
                        {
                            dnDir.mkdirs();
                        }

                        // export the items using normal export method
                        exportItem(context, iitems, workDir, 1, migrate);
                        // now zip up the export directory created above
                        zip(workDir, downloadDir
                                + System.getProperty("file.separator")
                                + fileName + ".zip");
                        // email message letting user know the file is ready for
                        // download
                        emailSuccessMessage(context, eperson, fileName + ".zip");
                        // return to enforcing auths
                        context.setIgnoreAuthorization(false);
                    }
                    catch (Exception e1)
                    {
                        try
                        {
                            emailErrorMessage(eperson, e1.getMessage());
                        }
                        catch (Exception e)
                        {
                            // wont throw here
                        }
                        throw new RuntimeException(e1);
                    }
                    finally
                    {
                        if (iitems != null)
                            iitems.close();
                       
                        // Make sure the database connection gets closed in all conditions.
                      try {
              context.complete();
            } catch (SQLException sqle) {
              context.abort();
            }
                    }
                }

            };
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.