Package org.dspace.content.packager

Examples of org.dspace.content.packager.PackageDisseminator


        else
        {
            OutputStream dest = (sourceFile.equals("-")) ? (OutputStream) System.out
                    : (OutputStream) (new FileOutputStream(sourceFile));

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

            DSpaceObject dso = HandleManager.resolveToObject(context,
                    itemHandle);
            if (dso == null)
                throw new IllegalArgumentException("Bad Item handle -- "
                        + "Cannot resolve handle \"" + itemHandle);
            dip.disseminate(context, dso, pkgParams, dest);
        }
    }
View Full Code Here


    {
        if (dso.getType() != Constants.ITEM)
            throw new CrosswalkObjectNotSupported("METSDisseminationCrosswalk can only crosswalk an Item.");
        Item item = (Item)dso;

        PackageDisseminator dip = (PackageDisseminator)
          PluginManager.getNamedPlugin(PackageDisseminator.class, METS_PACKAGER_PLUGIN);
        if (dip == null)
            throw new CrosswalkInternalException("Cannot find a disseminate plugin for package="+METS_PACKAGER_PLUGIN);

        try
        {
            // Set the manifestOnly=true param so we just get METS document
            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
            {
                SAXBuilder builder = new SAXBuilder();
View Full Code Here

        if (packageType == null)
        {
            packageType = "default";
        }
        PackageDisseminator dip = (PackageDisseminator) PluginManager
                .getNamedPlugin(PackageDisseminator.class, packageType);
        if (dip == null)
        {
            throw new DAVStatusException(HttpServletResponse.SC_BAD_REQUEST,
                    "Cannot find a disseminate plugin for package="
                            + packageType);
        }
        else
        {
            try
            {
                PackageParameters pparams = PackageParameters.create(this.request);
                this.response.setContentType(dip.getMIMEType(pparams));
                dip.disseminate(this.context, this.item, pparams, this.response
                        .getOutputStream());
            }
            catch (CrosswalkException pe)
            {
                throw new DAVStatusException(
View Full Code Here

     */
    public void createPackage(Context context, String handle, File file) throws InvalidHandleException, PackagerException, PackageFormatException
    {
        // Note - in the future we may need to allow for more than zipped up packages.

        PackageDisseminator dip = (PackageDisseminator) PluginManager
                .getNamedPlugin(PackageDisseminator.class, packageFormat);

        if (dip == null)
        {
            log.error("Error - unknown package type " + packageFormat);
            throw new PackageFormatException("Unknown package type " + packageFormat);
        }

        DSpaceObject dso = null;
        try
        {
            dso = HandleManager.resolveToObject(context, handle);
        }
        catch (SQLException e)
        {
            log.error("Unable to resolve handle " + handle);
            throw new InvalidHandleException("Unable to resolve handle " + handle);
        }

        if (dso == null)
        {
            log.error("Unable to resolve handle " + handle);
            throw new InvalidHandleException("Unable to resolve handle " + handle);
        }

        try
        {
            dip.disseminate(context, dso, pkgParams, file);
        }
        catch (Exception e)
        {
            log.error("Error creating package", e);
            throw new PackagerException("Error creating package", e);
View Full Code Here

        if (packageType == null)
        {
            packageType = "default";
        }
        PackageDisseminator dip = (PackageDisseminator) PluginManager
                .getNamedPlugin(PackageDisseminator.class, packageType);
        if (dip == null)
        {
            throw new DAVStatusException(HttpServletResponse.SC_BAD_REQUEST,
                    "Cannot find a disseminate plugin for package="
                            + packageType);
        }
        else
        {
            try
            {
                // Create a temporary file to disseminate into
                String tempDirectory = (ConfigurationManager.getProperty("upload.temp.dir") != null)
                    ? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
                File tempFile = File.createTempFile("DAVItemGet" + this.item.hashCode(), null, new File(tempDirectory));
                tempFile.deleteOnExit();

                // Disseminate item to temporary file
                PackageParameters pparams = PackageParameters.create(this.request);
                this.response.setContentType(dip.getMIMEType(pparams));
                dip.disseminate(this.context, this.item, pparams, tempFile);

                // Copy temporary file contents to response stream
                FileInputStream fileIn = null;
                try
                {
View Full Code Here

        throws CrosswalkException, IOException, SQLException,
               AuthorizeException
    {
        try
        {
            PackageDisseminator dip = (PackageDisseminator)
            PluginManager.getNamedPlugin(PackageDisseminator.class, ROLE_PACKAGER_PLUGIN);
            if (dip == null)
            {
                throw new CrosswalkInternalException("Cannot find a PackageDisseminator plugin named " + ROLE_PACKAGER_PLUGIN);
            }

            // Create a temporary file to disseminate into
            String tempDirectory = (ConfigurationManager.getProperty("upload.temp.dir") != null)
                ? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
            File tempFile = File.createTempFile("RoleCrosswalkDisseminate" + dso.hashCode(), null, new File(tempDirectory));
            tempFile.deleteOnExit();

            // Initialize our packaging parameters
            PackageParameters pparams;
            if(this.getPackagingParameters()!=null)
            {
                pparams = this.getPackagingParameters();
            }
            else
            {
                pparams = new PackageParameters();
            }

            //actually disseminate to our temp file.
            Context context = new Context();
            dip.disseminate(context, dso, pparams, tempFile);
            context.complete();
           
            // if we ended up with a Zero-length output file,
            // this means dissemination was successful but had no results
            if(tempFile.exists() && tempFile.length()==0)
View Full Code Here

        if (!canDisseminate(dso))
        {
            throw new CrosswalkObjectNotSupported("METSDisseminationCrosswalk cannot disseminate a DSpaceObject of type: " + Constants.typeText[dso.getType()]);
        }
       
        PackageDisseminator dip = (PackageDisseminator)
          PluginManager.getNamedPlugin(PackageDisseminator.class, METS_PACKAGER_PLUGIN);
        if (dip == null)
        {
            throw new CrosswalkInternalException("Cannot find a disseminate plugin for package=" + METS_PACKAGER_PLUGIN);
        }

        try
        {
            // Set the manifestOnly=true param so we just get METS document (and not content files, etc)
            PackageParameters pparams = new PackageParameters();
            pparams.put("manifestOnly", "true");

            // Create a temporary file to disseminate into
            String tempDirectory = (ConfigurationManager.getProperty("upload.temp.dir") != null)
                ? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");

            File tempFile = File.createTempFile("METSDissemination" + dso.hashCode(), null, new File(tempDirectory));
            tempFile.deleteOnExit();

            // Disseminate METS to temp file
            Context context = new Context();
            dip.disseminate(context, dso, pparams, tempFile);
            context.complete();

            try
            {
                //Return just the root Element of the METS file
View Full Code Here

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

            // validate each parent arg (if any)
            DSpaceObject parentObjs[] = null;
            if(parents!=null)
            {
                System.out.println("Destination parents:");

                parentObjs = new DSpaceObject[parents.length];
                for (int i = 0; i < parents.length; i++)
                {
                    // sanity check: did handle resolve?
                    parentObjs[i] = HandleManager.resolveToObject(context,
                            parents[i]);
                    if (parentObjs[i] == null)
                    {
                        throw new IllegalArgumentException(
                                "Bad parent list -- "
                                        + "Cannot resolve parent handle \""
                                        + parents[i] + "\"");
                    }
                    System.out.println((i == 0 ? "Owner: " : "Parent: ")
                            + parentObjs[i].getHandle());
                }
            }

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

                //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 DISSEMINATE mode
        else
        {
            //retrieve specified package disseminator
            PackageDisseminator dip = (PackageDisseminator) PluginManager
                .getNamedPlugin(PackageDisseminator.class, myPackager.packageType);
            if (dip == null)
            {
                usageError("Error, Unknown package type: " + myPackager.packageType);
            }
View Full Code Here

TOP

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

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.