Package org.dspace.content

Examples of org.dspace.content.Item


                            PackageParameters params, OutputStream pkg)
        throws PackageValidationException, CrosswalkException, AuthorizeException, SQLException, IOException
    {
        if (dso.getType() == Constants.ITEM)
        {
            Item item = (Item)dso;
            long lmTime = item.getLastModified().getTime();

            // how to handle unauthorized bundle/bitstream:
            String unauth = (params == null) ? null : params.getProperty("unauthorized");

            if (params != null && params.getProperty("manifestOnly") != null)
            {
                extraFiles = null;
                writeManifest(context, item, params, pkg);
            }
            else
            {
                extraFiles = new HashMap();
                ZipOutputStream zip = new ZipOutputStream(pkg);
                zip.setComment("METS archive created by DSpace METSDisseminationCrosswalk");

                // write manifest first.
                ZipEntry me = new ZipEntry(MANIFEST_FILE);
                me.setTime(lmTime);
                zip.putNextEntry(me);
                writeManifest(context, item, params, zip);
                zip.closeEntry();
               
                // copy extra (meta?) bitstreams into zip
                Iterator fi = extraFiles.keySet().iterator();
                while (fi.hasNext())
                {
                    String fname = (String)fi.next();
                    ZipEntry ze = new ZipEntry(fname);
                    ze.setTime(lmTime);
                    zip.putNextEntry(ze);
                    Utils.copy((InputStream)extraFiles.get(fname), zip);
                    zip.closeEntry();
                }

                // copy all non-meta bitstreams into zip
                Bundle bundles[] = item.getBundles();
                for (int i = 0; i < bundles.length; i++)
                {
                    if (!PackageUtils.isMetaInfoBundle(bundles[i]))
                    {
                        // unauthorized bundle?
View Full Code Here


     * @return the workspace item
     */
    private static WorkspaceItem returnToWorkspace(Context c, WorkflowItem wfi)
            throws SQLException, IOException, AuthorizeException
    {
        Item myitem = wfi.getItem();
        Collection mycollection = wfi.getCollection();

        // FIXME: How should this interact with the workflow system?
        // FIXME: Remove license
        // FIXME: Provenance statement?
        // Create the new workspace item row
        TableRow row = DatabaseManager.create(c, "workspaceitem");
        row.setColumn("item_id", myitem.getID());
        row.setColumn("collection_id", mycollection.getID());
        DatabaseManager.update(c, row);

        int wsi_id = row.getIntColumn("workspace_item_id");
        WorkspaceItem wi = WorkspaceItem.find(c, wsi_id);
View Full Code Here

        // authorize a DSpaceActions.REJECT
        // stop workflow
        deleteTasks(c, wi);

        // rejection provenance
        Item myitem = wi.getItem();

        // Get current date
        String now = DCDate.getCurrent().toString();

        // Get user's name + email address
        String usersName = getEPersonName(e);

        // Here's what happened
        String provDescription = "Rejected by " + usersName + ", reason: "
                + rejection_message + " on " + now + " (GMT) ";

        // Add to item as a DC field
        myitem.addDC("description", "provenance", "en", provDescription);
        myitem.update();

        // convert into personal workspace
        WorkspaceItem wsi = returnToWorkspace(c, wi);

        // notify that it's been rejected
View Full Code Here

     *
     * @param wi  the workflow item object
     */
    public static String getItemTitle(WorkflowItem wi) throws SQLException
    {
        Item myitem = wi.getItem();
        DCValue[] titles = myitem.getDC("title", null, Item.ANY);

        // only return the first element, or "Untitled"
        if (titles.length > 0)
        {
            return titles[0].value;
View Full Code Here

    // Record approval provenance statement
    private static void recordApproval(Context c, WorkflowItem wi, EPerson e)
            throws SQLException, IOException, AuthorizeException
    {
        Item item = wi.getItem();

        // Get user's name + email address
        String usersName = getEPersonName(e);

        // Get current date
        String now = DCDate.getCurrent().toString();

        // Here's what happened
        String provDescription = "Approved for entry into archive by "
                + usersName + " on " + now + " (GMT) ";

        // add bitstream descriptions (name, size, checksums)
        provDescription += InstallItem.getBitstreamProvenanceMessage(item);

        // Add to item as a DC field
        item.addDC("description", "provenance", "en", provDescription);
        item.update();
    }
View Full Code Here

   
    Date timeStart = new Date();
   
    if (dso.getType() != Constants.ITEM)
            throw new CrosswalkObjectNotSupported("OREIngestionCrosswalk can only crosswalk an Item.");
        Item item = (Item)dso;
       
        if (root == null) {
          System.err.println("The element received by ingest was null");
          return;
        }
               
        Document doc = new Document();
        doc.addContent(root.detach());
       
        XPath xpathLinks;
        List<Element> aggregatedResources;
        String entryId;
    try {
      xpathLinks = XPath.newInstance("/atom:entry/atom:link[@rel=\"" + ORE_NS.getURI()+"aggregates" + "\"]");
      xpathLinks.addNamespace(ATOM_NS);
          aggregatedResources = xpathLinks.selectNodes(doc);
         
          xpathLinks = XPath.newInstance("/atom:entry/atom:link[@rel='alternate']/@href");
          xpathLinks.addNamespace(ATOM_NS);
          entryId = ((Attribute)xpathLinks.selectSingleNode(doc)).getValue();
    } catch (JDOMException e) {
      throw new CrosswalkException("JDOM exception occured while ingesting the ORE");
    }

    // Next for each resource, create a bitstream
      XPath xpathDesc;
      NumberFormat nf=NumberFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(4)
   
      int countInt=0;
      String count;
        for (Element resource : aggregatedResources)
        {
          countInt++;
          count = nf.format((long)countInt);
          String href = resource.getAttributeValue("href");
          log.debug("ORE processing: " + href);
         
          String bundleName;
          Element desc = null;
          try {
            xpathDesc = XPath.newInstance("/atom:entry/oreatom:triples/rdf:Description[@rdf:about=\"" + this.URLencode(href) + "\"][1]");
            xpathDesc.addNamespace(ATOM_NS);
            xpathDesc.addNamespace(ORE_ATOM);
            xpathDesc.addNamespace(RDF_NS);
            desc = (Element)xpathDesc.selectSingleNode(doc);
          } catch (JDOMException e) {
            e.printStackTrace();
          }
         
          if (desc != null && desc.getChild("type", RDF_NS).getAttributeValue("resource", RDF_NS).equals(DS_NS.getURI() + "DSpaceBitstream"))
          {
            bundleName = desc.getChildText("description", DCTERMS_NS);
            log.debug("Setting bundle name to: " + bundleName);
          }
          else {
            log.info("Could not obtain bundle name; using 'ORIGINAL'");
            bundleName = "ORIGINAL";
          }
         
          // Bundle names are not unique, so we just pick the first one if there's more than one.
          Bundle[] targetBundles = item.getBundles(bundleName);
          Bundle targetBundle;
         
          // if null, create the new bundle and add it in
          if (targetBundles.length == 0) {
            targetBundle = item.createBundle(bundleName);
            item.addBundle(targetBundle);
          }
          else {
            targetBundle = targetBundles[0];
          }
         
          URL ARurl = null;
          InputStream in = null;
          if (href != null) {
            try {
              // Make sure the url string escapes all the oddball characters
              String processedURL = URLencode(href);
              // Generate a requeset for the aggregated resource
              ARurl = new URL(processedURL);
              in = ARurl.openStream();
            }
            catch(FileNotFoundException fe) {
                log.error("The provided URI failed to return a resource: " + href);
              }
            catch(ConnectException fe) {
                log.error("The provided URI was invalid: " + href);
              }
          }
          else {
            throw new CrosswalkException("Entry did not contain link to resource: " + entryId);
          }
         
          // ingest and update
          if (in != null) {
            Bitstream newBitstream = targetBundle.createBitstream(in);
           
            String bsName = resource.getAttributeValue("title");
            newBitstream.setName(bsName);
           
              // Identify the format
            String mimeString = resource.getAttributeValue("type");
            BitstreamFormat bsFormat = BitstreamFormat.findByMIMEType(context, mimeString);
            if (bsFormat == null) {
              bsFormat = FormatIdentifier.guessFormat(context, newBitstream);
            }
            newBitstream.setFormat(bsFormat);
              newBitstream.update();
             
              targetBundle.addBitstream(newBitstream);
            targetBundle.update();
          }
          else {
            throw new CrosswalkException("Could not retrieve bitstream: " + entryId);
          }
         
        }
        log.info("OREIngest for Item "+ item.getID() + " took: " + (new Date().getTime() - timeStart.getTime()) + "ms.");
  }
View Full Code Here

        ItemIterator iterator = collection.getItems();
        try
        {
            while (iterator.hasNext())
            {
                Item item = iterator.next();

                if (! item.isOwningCollection(collection))
                    items.add(item);
            }
        }
        finally
        {
View Full Code Here

  public void ingest(Context context, DSpaceObject dso, Element root) throws CrosswalkException, IOException, SQLException, AuthorizeException {
   
    if (dso.getType() != Constants.ITEM)
            throw new CrosswalkObjectNotSupported("DIMIngestionCrosswalk can only crosswalk an Item.");
        Item item = (Item)dso;
       
        if (root == null) {
          System.err.println("The element received by ingest was null");
          return;
        }
       
        List<Element> metadata = root.getChildren();
        for (Element element : metadata) {
          item.addMetadata("dc", element.getName(), null, null, element.getText());
        }
       
  }
View Full Code Here

        {
            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.");
                            }
                        }
                    }
                }
View Full Code Here

   
   
    public String createMetadata(Object nativeItem)
        throws CannotDisseminateFormatException
    {
        Item item = ((HarvestedItemInfo) nativeItem).item;
      
        StringBuffer metadata = new StringBuffer();
        String itemhandle=item.getHandle();
        String strMaxSize = ConfigurationManager.getProperty("oai.didl.maxresponse");
        int maxsize = MAXRESPONSE_INLINE_BITSTREAM;
        if (strMaxSize != null)
        {
            maxsize = Integer.parseInt(strMaxSize);
        }
        
        String currdate=ServerVerb.createResponseDate(new Date());
       
        metadata.append("<didl:DIDL ")
            .append(" xmlns:didl=\"urn:mpeg:mpeg21:2002:02-DIDL-NS\"  ")
            .append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
            .append("xsi:schemaLocation=\"urn:mpeg:mpeg21:2002:02-DIDL-NS http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-21_schema_files/did/didl.xsd \">")
            .append ("<didl:DIDLInfo>")
            .append ("<dcterms:created xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://purl.org/dc/terms/ \">")
            .append  (currdate)
            .append ("</dcterms:created> </didl:DIDLInfo>" )
            .append("<didl:Item id=\"")
            .append("uuid-" + UUIDFactory.generateUUID().toString()+"\">");
        metadata.append("<didl:Descriptor>")
            .append("<didl:Statement mimeType=\"application/xml; charset=utf-8\">")
            .append("<dii:Identifier xmlns:dii=\"urn:mpeg:mpeg21:2002:01-DII-NS\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:mpeg:mpeg21:2002:01-DII-NS http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-21_schema_files/dii/dii.xsd\">")
            .append("urn:hdl:" + itemhandle)
            .append("</dii:Identifier>")
            .append("</didl:Statement>")
            .append("</didl:Descriptor>");
        metadata.append("<didl:Descriptor>")
            .append("<didl:Statement mimeType=\"application/xml; charset=utf-8\">");
         
        // delegate the metadata section to another crosswalk
        metadata.append(metadataCrosswalk.createMetadata(nativeItem));
       
        metadata
            .append("</didl:Statement>")
            .append("</didl:Descriptor>");       
       
        /**putfirst item here**/
       
       
        //**CYCLE HERE!!!!**//
      
        try
        {
            Bundle[] bundles= item.getBundles("ORIGINAL");   
           
            if (bundles.length != 0)
            {
              /**cycle bundles**/
                for (int i = 0; i < bundles.length; i++)
View Full Code Here

TOP

Related Classes of org.dspace.content.Item

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.