Package org.dspace.content.packager

Examples of org.dspace.content.packager.PackageIngester


        {
            // make sure we have an input file
            InputStream source = (sourceFile.equals("-")) ? System.in
                    : new FileInputStream(sourceFile);

            PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, packageType);
            if (sip == null)
                usageError("Error, Unknown package type: " + packageType);

            // find collections
            Collection[] mycollections = null;

            System.out.println("Destination collections:");

            // validate each collection arg to see if it's a real collection
            mycollections = new Collection[collections.length];
            for (int i = 0; i < collections.length; i++)
            {
                // sanity check: did handle resolve, and to a collection?
                DSpaceObject dso = HandleManager.resolveToObject(context,
                        collections[i]);
                if (dso == null)
                    throw new IllegalArgumentException(
                            "Bad collection list -- "
                                    + "Cannot resolve collection handle \""
                                    + collections[i] + "\"");
                else if (dso.getType() != Constants.COLLECTION)
                    throw new IllegalArgumentException(
                            "Bad collection list -- " + "Object at handle \""
                                    + collections[i]
                                    + "\" is not a collection!");
                mycollections[i] = (Collection) dso;
                System.out.println((i == 0 ? "  Owning " : "  ")
                        + " Collection: "
                        + mycollections[i].getMetadata("name"));
            }

            try
            {
                WorkspaceItem wi = sip.ingest(context, mycollections[0],
                        source, pkgParams, null);
                if (useWorkflow)
                {
                    String handle = null;
View Full Code Here


                throw new DAVStatusException(
                        HttpServletResponse.SC_BAD_REQUEST,
                        "Cannot determine package type,  need content-type header or package param");
            }

            PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, packageType);
            if (sip == null)
            {
                throw new DAVStatusException(
                        HttpServletResponse.SC_BAD_REQUEST,
                        "Cannot find importer for package type: " + packageType);
            }

            /*
             * Ugh. Servlet container doesn't get end-of-file right on input
             * stream so we have to count it, when possible.
             */
            int contentLength = this.request.getIntHeader("Content-Length");
            InputStream pis = this.request.getInputStream();
            if (contentLength >= 0)
            {
                pis = new CountedInputStream(pis, contentLength);
                log.debug("put: Using CountedInputStream, length="
                        + String.valueOf(contentLength));
            }
            WorkspaceItem wi = sip.ingest(this.context, this.collection, pis,
                    PackageParameters.create(this.request), null);
            WorkflowItem wfi = WorkflowManager.startWithoutNotify(this.context, wi);

            // get new item's location: if workflow completed, then look
            // for handle (but be ready for disappointment); otherwise,
View Full Code Here

      {
        cfg = "METS"// default to METS
      }
      swordService.message("Using package manifest format: " + cfg);
     
      PackageIngester pi = (PackageIngester) PluginManager.getNamedPlugin(PackageIngester.class, cfg);
      swordService.message("Loaded package ingester: " + pi.getClass().getName());
     
      // the licence is either in the zip or the mets manifest.  Either way
      // it's none of our business here
      String licence = null;
     
      // We don't need to include any parameters
      PackageParameters params = new PackageParameters();
     
      // ingest the item
      WorkspaceItem wsi = pi.ingest(context, collection, is, params, licence);
      if (wsi == null)
      {
        swordService.message("Failed to ingest the package; throwing exception");
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
      }
View Full Code Here

                throw new DAVStatusException(
                        HttpServletResponse.SC_BAD_REQUEST,
                        "Cannot determine package type,  need content-type header or package param");
            }

            PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, packageType);
            if (sip == null)
            {
                throw new DAVStatusException(
                        HttpServletResponse.SC_BAD_REQUEST,
                        "Cannot find importer for package type: " + packageType);
            }

            /*
             * Ugh. Servlet container doesn't get end-of-file right on input
             * stream so we have to count it, when possible.
             */
            int contentLength = this.request.getIntHeader("Content-Length");
            InputStream pis = this.request.getInputStream();
            if (contentLength >= 0)
            {
                pis = new CountedInputStream(pis, contentLength);
                log.debug("put: Using CountedInputStream, length="
                        + String.valueOf(contentLength));
            }

            // Write to temporary file (so that SIP ingester can process it)
            File tempDir = new File(tempDirectory);
            File tempFile = File.createTempFile("davUpload" + pis.hashCode(), null, tempDir);
            log.debug("Storing temporary file at " + tempFile.getCanonicalPath());

            FileOutputStream fos = new FileOutputStream(tempFile);
            Utils.copy(pis, fos);
            fos.close();
            pis.close();

            // Initialize parameters to packager
            PackageParameters params = PackageParameters.create(this.request);
            // Force package ingester to respect Collection workflows (i.e. start workflow automatically as needed)
            params.setWorkflowEnabled(true);

            //ingest from the temp file to create the new DSpaceObject
            DSpaceObject ingestedDso = sip.ingest(this.context, this.collection, tempFile,
                    params, null);
            Item item = (Item) ingestedDso;

            //schedule temp file for deletion
            tempFile.deleteOnExit();
View Full Code Here

        {
            throw new CrosswalkObjectNotSupported("Role crosswalk only valid for Site, Community or Collection");
        }

        //locate our "DSPACE-ROLES" PackageIngester plugin
        PackageIngester sip = (PackageIngester)
                                PluginManager.getNamedPlugin(PackageIngester.class, ROLE_PACKAGER_PLUGIN);
        if (sip == null)
        {
            throw new CrosswalkInternalException("Cannot find a PackageIngester plugin named " + ROLE_PACKAGER_PLUGIN);
        }

        // Initialize our packaging parameters
        PackageParameters pparams;
        if(this.getPackagingParameters()!=null)
        {
            pparams = this.getPackagingParameters();
        }
        else
        {
            pparams = new PackageParameters();
        }
       
        // Initialize our license info
        String license = null;
        if(this.getIngestionLicense()!=null)
        {
            license = this.getIngestionLicense();
        }
       
        // Create a temporary file to ingest from
        String tempDirectory = (ConfigurationManager.getProperty("upload.temp.dir") != null)
            ? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
        File tempFile = File.createTempFile("RoleCrosswalkIngest" + dso.hashCode(), null, new File(tempDirectory));
        tempFile.deleteOnExit();
        FileOutputStream fileOutStream = null;
        try
        {
            fileOutStream = new FileOutputStream(tempFile);
            XMLOutputter writer = new XMLOutputter();
            writer.output(root, fileOutStream);
        }
        finally
        {
            if (fileOutStream != null)
            {
                fileOutStream.close();
            }
        }

        //Actually call the ingester
        try
        {
            sip.ingest(context, dso, tempFile, pparams, license);
        }
        catch (PackageException e)
        {
            throw new CrosswalkInternalException(e);
        }
View Full Code Here

      {
        cfg = "METS"// default to METS
      }
      swordService.message("Using package manifest format: " + cfg);
     
      PackageIngester pi = (PackageIngester) PluginManager.getNamedPlugin(PackageIngester.class, cfg);
      swordService.message("Loaded package ingester: " + pi.getClass().getName());
     
      // the licence is either in the zip or the mets manifest.  Either way
      // it's none of our business here
      String licence = null;
     
      // Initialize parameters to packager
      PackageParameters params = new PackageParameters();

            // Force package ingester to respect Collection workflows
            params.setWorkflowEnabled(true);

            // Should restore mode be enabled, i.e. keep existing handle?
            if (ConfigurationManager.getBooleanProperty("sword-server", "restore-mode.enable",false))
            {
                params.setRestoreModeEnabled(true);
            }

            // Whether or not to use the collection template
            params.setUseCollectionTemplate(ConfigurationManager.getBooleanProperty("mets.default.ingest.useCollectionTemplate", false));
     
      // ingest the item from the temp file
      DSpaceObject ingestedObject = pi.ingest(context, collection, depositFile, params, licence);
      if (ingestedObject == null)
      {
        swordService.message("Failed to ingest the package; throwing exception");
        throw new SWORDErrorException(DSpaceSWORDErrorCodes.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
      }
View Full Code Here

                System.out.println("\n--------------------------------------------------------------");
                System.out.println("Additional options for the " + line.getOptionValue('t') + " packager:");
                System.out.println("--------------------------------------------------------------");
                System.out.println("(These options may be specified using --option as described above)");

                PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, line.getOptionValue('t'));

                if (sip != null)
                {
                    System.out.println("\n\n" + line.getOptionValue('t') + " Submission (SIP) plugin options:\n");
                    System.out.println(sip.getParameterHelp());
                }
                else
                {
                    System.out.println("\nNo valid Submission plugin found for " + line.getOptionValue('t') + " type.");
                }

                PackageDisseminator dip = (PackageDisseminator) PluginManager
                    .getNamedPlugin(PackageDisseminator.class, line.getOptionValue('t'));

                if (dip != null)
                {
                    System.out.println("\n\n" + line.getOptionValue('t') + " Dissemination (DIP) plugin options:\n");
                    System.out.println(dip.getParameterHelp());
                }
                else
                {
                    System.out.println("\nNo valid Dissemination plugin found for " + line.getOptionValue('t') + " type.");
                }

            }
            else  //otherwise, display list of valid packager types
            {
                System.out.println("\nAvailable Submission Package (SIP) types:");
                String pn[] = PluginManager
                        .getAllPluginNames(PackageIngester.class);
                for (int i = 0; i < pn.length; ++i)
                {
                    System.out.println("  " + pn[i]);
                }
                System.out
                        .println("\nAvailable Dissemination Package (DIP) types:");
                pn = PluginManager.getAllPluginNames(PackageDisseminator.class);
                for (int i = 0; i < pn.length; ++i)
                {
                    System.out.println("  " + pn[i]);
                }
            }
            System.exit(0);
        }

        //look for flag to disable all user interaction
        if(line.hasOption('u'))
        {
            myPackager.userInteractionEnabled = false;
        }
        if (line.hasOption('w'))
        {
            pkgParams.setWorkflowEnabled(false);
        }
        if (line.hasOption('r'))
        {
            pkgParams.setRestoreModeEnabled(true);
        }
        //keep-existing is only valid in restoreMode (-r) -- otherwise ignore -k option.
        if (line.hasOption('k') && pkgParams.restoreModeEnabled())
        {
            pkgParams.setKeepExistingModeEnabled(true);
        }
        //force-replace is only valid in restoreMode (-r) -- otherwise ignore -f option.
        if (line.hasOption('f') && pkgParams.restoreModeEnabled())
        {
            pkgParams.setReplaceModeEnabled(true);
        }
        if (line.hasOption('e'))
        {
            eperson = line.getOptionValue('e');
        }
        if (line.hasOption('p'))
        {
            parents = line.getOptionValues('p');
        }
        if (line.hasOption('t'))
        {
            myPackager.packageType = line.getOptionValue('t');
        }
        if (line.hasOption('i'))
        {
            identifier = line.getOptionValue('i');
        }
        if (line.hasOption('a'))
        {
            //enable 'recursiveMode' param to packager implementations, in case it helps with packaging or ingestion process
            pkgParams.setRecursiveModeEnabled(true);
        }
        String files[] = line.getArgs();
        if (files.length > 0)
        {
            sourceFile = files[0];
        }
        if (line.hasOption('d'))
        {
            myPackager.submit = false;
        }
        if (line.hasOption('o'))
        {
            String popt[] = line.getOptionValues('o');
            for (int i = 0; i < popt.length; ++i)
            {
                String pair[] = popt[i].split("\\=", 2);
                if (pair.length == 2)
                {
                    pkgParams.addProperty(pair[0].trim(), pair[1].trim());
                }
                else if (pair.length == 1)
                {
                    pkgParams.addProperty(pair[0].trim(), "");
                }
                else
                {
                    System.err
                            .println("Warning: Illegal package option format: \""
                                    + popt[i] + "\"");
                }
            }
        }

        // Sanity checks on arg list: required args
        // REQUIRED: sourceFile, ePerson (-e), packageType (-t)
        if (sourceFile == null || eperson == null || myPackager.packageType == null)
        {
            System.err.println("Error - missing a REQUIRED argument or option.\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("PackageManager  [options]  package-file|-\n", options);
            System.exit(0);
        }

        // find the EPerson, assign to context
        Context context = new Context();
        EPerson myEPerson = null;
        myEPerson = EPerson.findByEmail(context, eperson);
        if (myEPerson == null)
        {
            usageError("Error, eperson cannot be found: " + eperson);
        }
        context.setCurrentUser(myEPerson);


        //If we are in REPLACE mode
        if(pkgParams.replaceModeEnabled())
        {
            PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, myPackager.packageType);
            if (sip == null)
            {
                usageError("Error, Unknown package type: " + myPackager.packageType);
            }

            DSpaceObject objToReplace = null;

            //if a specific identifier was specified, make sure it is valid
            if(identifier!=null && identifier.length()>0)
            {
                objToReplace = HandleManager.resolveToObject(context, identifier);
                if (objToReplace == null)
                {
                    throw new IllegalArgumentException("Bad identifier/handle -- "
                            + "Cannot resolve handle \"" + identifier + "\"");
                }
            }

            String choiceString = null;
            if(myPackager.userInteractionEnabled)
            {
                BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("\n\nWARNING -- You are running the packager in REPLACE mode.");
                System.out.println("\nREPLACE mode may be potentially dangerous as it will automatically remove and replace contents within DSpace.");
                System.out.println("We highly recommend backing up all your DSpace contents (files & database) before continuing.");
                System.out.print("\nWould you like to continue? [y/n]: ");
                choiceString = input.readLine();
            }
            else
            {
                //user interaction disabled -- default answer to 'yes', otherwise script won't continue
                choiceString = "y";
            }

            if (choiceString.equalsIgnoreCase("y"))
            {
                System.out.println("Beginning replacement process...");

                try
                {
                    //replace the object from the source file
                    myPackager.replace(context, sip, pkgParams, sourceFile, objToReplace);

                    //commit all changes & exit successfully
                    context.complete();
                    System.exit(0);
                }
                catch (Exception e)
                {
                    // abort all operations
                    e.printStackTrace();
                    context.abort();
                    System.out.println(e);
                    System.exit(1);
                }
            }

        }
        //else if normal SUBMIT mode (or basic RESTORE mode -- which is a special type of submission)
        else if (myPackager.submit || pkgParams.restoreModeEnabled())
        {
            PackageIngester sip = (PackageIngester) PluginManager
                    .getNamedPlugin(PackageIngester.class, myPackager.packageType);
            if (sip == null)
            {
                usageError("Error, Unknown package type: " + myPackager.packageType);
            }
View Full Code Here

      {
        cfg = "METS"// default to METS
      }
      verboseDescription.append("Using package manifest format: " + cfg);

      PackageIngester pi = (PackageIngester) PluginManager.getNamedPlugin(PackageIngester.class, cfg);
      verboseDescription.append("Loaded package ingester: " + pi.getClass().getName());

      // Initialize parameters to packager
      PackageParameters params = new PackageParameters();

            // Force package ingester to respect Collection workflows
            params.setWorkflowEnabled(true);

            // Should restore mode be enabled, i.e. keep existing handle?
            if (ConfigurationManager.getBooleanProperty("sword-server", "restore-mode.enable",false))
            {
                params.setRestoreModeEnabled(true);
            }

            // Whether or not to use the collection template
            params.setUseCollectionTemplate(ConfigurationManager.getBooleanProperty("mets.default.ingest.useCollectionTemplate", false));

      // ingest the item from the temp file
      DSpaceObject ingestedObject = pi.replace(context, item, depositFile, params);
      if (ingestedObject == null)
      {
        verboseDescription.append("Failed to ingest the package; throwing exception");
                throw new SwordError(DSpaceUriRegistry.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
      }
View Full Code Here

      {
        cfg = "METS"// default to METS
      }
      verboseDescription.append("Using package manifest format: " + cfg);

      PackageIngester pi = (PackageIngester) PluginManager.getNamedPlugin(PackageIngester.class, cfg);
      verboseDescription.append("Loaded package ingester: " + pi.getClass().getName());

      // Initialize parameters to packager
      PackageParameters params = new PackageParameters();

            // Force package ingester to respect Collection workflows
            params.setWorkflowEnabled(true);

            // Should restore mode be enabled, i.e. keep existing handle?
            if (ConfigurationManager.getBooleanProperty("sword-server", "restore-mode.enable",false))
            {
                params.setRestoreModeEnabled(true);
            }

            // Whether or not to use the collection template
            params.setUseCollectionTemplate(ConfigurationManager.getBooleanProperty("mets.default.ingest.useCollectionTemplate", false));

      // ingest the item from the temp file
      DSpaceObject ingestedObject = pi.replace(context, item, depositFile, params);
      if (ingestedObject == null)
      {
        verboseDescription.append("Failed to replace the package; throwing exception");
                throw new SwordError(DSpaceUriRegistry.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
      }
View Full Code Here

TOP

Related Classes of org.dspace.content.packager.PackageIngester

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.