Package org.dspace.content

Examples of org.dspace.content.Item


            AuthorizeException
    {
        DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
        if (!(dso instanceof Item))
            return;
        Item item = (Item) dso;

        // Set the page title
        String title = getItemTitle(item);
        if (title != null)
            pageMeta.addMetadata("title").addContent(title);
        else
            pageMeta.addMetadata("title").addContent(item.getHandle());

        // Set the page author
        String author = getItemAuthor(item);
        if (author != null)
            pageMeta.addMetadata("author").addContent(author);
View Full Code Here


    {

        DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
        if (!(dso instanceof Item))
            return;
        Item item = (Item) dso;

        // Build the item viewer division.
        Division division = body.addDivision("item-view","primary");
        String title = getItemTitle(item);
        if (title != null)
            division.setHead(title);
        else
            division.setHead(item.getHandle());

        /*
        Para showfullPara = division.addPara(null, "item-view-toggle item-view-toggle-top");

        if (showFullItem(objectModel))
        {
            String link = contextPath + "/handle/" + item.getHandle();
            showfullPara.addXref(link).addContent(T_show_simple);
        }
        else
        {
            String link = contextPath + "/handle/" + item.getHandle()
                    + "?show=full";
            showfullPara.addXref(link).addContent(T_show_full);
        }*/

       
        ReferenceSet referenceSet;
//        if (showFullItem(objectModel))
//        {
            referenceSet = division.addReferenceSet("collection-viewer",
                    ReferenceSet.TYPE_DETAIL_VIEW);
//        }
//        else
//        {
//            referenceSet = division.addReferenceSet("collection-viewer",
//                    ReferenceSet.TYPE_SUMMARY_VIEW);
//        }


        // Refrence the actual Item
        //referenceSet.addReference(item);


        /*
            reference any isPartOf items to create listing...

         */

        ReferenceSet appearsInclude = referenceSet.addReference(item).addReferenceSet(ReferenceSet.TYPE_DETAIL_LIST,null,"hierarchy");

        appearsInclude.setHead(T_head_parent_collections);


        // Reference all collections the item appears in.
        for (Collection collection : item.getCollections())
        {
            appearsInclude.addReference(collection);
        }
    }
View Full Code Here

          dso = items[0];
        }
       
        if (dso instanceof Item)
        {
            Item item = (Item) dso;
            Collection collection = item.getOwningCollection();
            dso = collection;
        }

        if (dso instanceof Collection)
        {
View Full Code Here

                    String group_by = this.getParameterGroup();
                    // If we are grouping, attempt to acquire the dc.isPartOf parent of the Item and group on it.
                    // Otherwise, Group on the current Item.
                    // TODO: this is a hack to always make sure any subItem is grouped under its parent
                    if (!group_by.equals("none")) {
                        Item parent = getParent((Item) resultDSO);
                        // if parent not null, use parent otherwise use existing item.
                        if (parent != null) {
                            Reference parentRef = referenceSet.addReference(parent);
                            addCollapsedDocuments(parentRef, parent, doc);
                    } else {
View Full Code Here

                        else
                        {
                               id = Integer.valueOf(parts[1]);
               if ("item".equals(type))
               {
                 Item item = Item.find(context,id);
                 if (item != null)
                                                 adapter = new ItemAdapter(context,item,contextPath);
               }
               else if ("collection".equals(type))
               {
View Full Code Here

            // We have a modified item check for a withdraw/reinstate
        }
        else if (eventType == Event.MODIFY_METADATA
                && event.getSubjectType() == Constants.ITEM)
        {
            Item item = Item.find(ctx, event.getSubjectID());

            String updateQuery = "id:" + item.getID() + " AND type:"
                    + item.getType();
            Map<String, List<String>> indexedValues = SolrLogger.queryField(
                    updateQuery, null, null);

            // Get all the metadata
            Map metadataStorageInfo = SolrLogger.getMetadataStorageInfo();
            List<String> storageFieldList = new ArrayList<String>();
            List<List<Object>> storageValuesList = new ArrayList<List<Object>>();

            for (Object storageField : metadataStorageInfo.keySet())
            {
                String[] metadataFieldInfo = String.valueOf(
                        metadataStorageInfo.get(storageField)).split("\\.");

                List<Object> values = new ArrayList<Object>();
                List<Object> valuesLow = new ArrayList<Object>();
                for (int i = 0; i < item.getMetadata(metadataFieldInfo[0],
                        metadataFieldInfo[1], metadataFieldInfo[2], Item.ANY).length; i++)
                {
                    values.add(item.getMetadata(metadataFieldInfo[0],
                            metadataFieldInfo[1], metadataFieldInfo[2],
                            Item.ANY)[i].value);
                   
                    valuesLow.add(item.getMetadata(metadataFieldInfo[0],
                            metadataFieldInfo[1], metadataFieldInfo[2],
                            Item.ANY)[i].value.toLowerCase());
                }

                List<String> indexedVals = indexedValues.get("" + storageField);

                boolean update = true;
                if (values.containsAll(indexedVals)
                        && values.size() == indexedVals.size())
                    update = false;

                if (update)
                {
                    storageFieldList.add((String) storageField);
                    storageFieldList.add(storageField + "_search");
                    storageValuesList.add(values);
                    storageValuesList.add(valuesLow);
                }
            }

            SolrLogger.update(updateQuery, "replace", storageFieldList,
                    storageValuesList);

        }

        if (eventType == Event.ADD && dsoType == Constants.COLLECTION
                && event.getObject(ctx) instanceof Item)
        {
            // We are mapping a new item make sure that the owning collection is
            // updated
            Item newItem = (Item) event.getObject(ctx);
            String updateQuery = "id: " + newItem.getID() + " AND type:"
                    + newItem.getType();

            List<String> fieldNames = new ArrayList<String>();
            List<List<Object>> valuesList = new ArrayList<List<Object>>();
            fieldNames.add("owningColl");
            fieldNames.add("owningComm");

            List<Object> valsList = new ArrayList<Object>();
            valsList.add(dsoId);
            valuesList.add(valsList);

            valsList = new ArrayList<Object>();
            valsList.addAll(findOwningCommunities(ctx, dsoId));
            valuesList.add(valsList);

            // Now make sure we also update the communities
            SolrLogger.update(updateQuery, "addOne", fieldNames, valuesList);

        }
        else if (eventType == Event.REMOVE && dsoType == Constants.COLLECTION
                && event.getObject(ctx) instanceof Item)
        {
            // Unmapping items
            Item newItem = (Item) event.getObject(ctx);
            String updateQuery = "id: " + newItem.getID() + " AND type:"
                    + newItem.getType();

            List<String> fieldNames = new ArrayList<String>();
            List<List<Object>> valuesList = new ArrayList<List<Object>>();
            fieldNames.add("owningColl");
            fieldNames.add("owningComm");
View Full Code Here

      // grab the oai identifier
      String itemOaiID = record.getChild("header", OAI_NS).getChild("identifier", OAI_NS).getText();
      Element header = record.getChild("header",OAI_NS);
     
      // look up the item corresponsing to the OAI identifier
      Item item = HarvestedItem.getItemByOAIId(ourContext, itemOaiID, targetCollection.getID());
           
      // Make sure the item hasn't been deleted in the mean time
    if (header.getAttribute("status") != null && header.getAttribute("status").getValue().equals("deleted")) {
      log.info("Item " + itemOaiID + " has been marked as deleted on the OAI server.");
      if (item != null)
        targetCollection.removeItem(item);
     
      ourContext.restoreAuthSystemState();     
      return;
    }
     
    // If we are only harvesting descriptive metadata, the record should already contain all we need
      List<Element> descMD = record.getChild("metadata", OAI_NS).getChildren();
      IngestionCrosswalk MDxwalk = (IngestionCrosswalk)PluginManager.getNamedPlugin(IngestionCrosswalk.class, this.metadataKey);
     
      // Otherwise, obtain the ORE ReM and initiate the ORE crosswalk
      IngestionCrosswalk ORExwalk = null;
      Element oreREM = null;
      if (harvestRow.getHarvestType() > 1) {
        oreREM = getMDrecord(harvestRow.getOaiSource(), itemOaiID, OREPrefix).get(0);
        ORExwalk = (IngestionCrosswalk)PluginManager.getNamedPlugin(IngestionCrosswalk.class, this.ORESeialKey);
      }
     
      // Ignore authorization
      ourContext.turnOffAuthorisationSystem();
     
      HarvestedItem hi;
     
      if (item != null) // found an item so we modify
     
        log.debug("Item " + item.getHandle() + " was found locally. Using it to harvest " + itemOaiID + ".");
       
        // FIXME: check for null pointer if for some odd reason we don't have a matching hi
        hi = HarvestedItem.find(ourContext, item.getID());
       
        // Comprate last-harvest on the item versus the last time the item was updated on the OAI provider side
      // If ours is more recent, forgo this item, since it's probably a left-over from a previous harvesting attempt
      Date OAIDatestamp = Utils.parseISO8601Date(header.getChildText("datestamp", OAI_NS));
      Date itemLastHarvest = hi.getHarvestDate();
      if (itemLastHarvest != null && OAIDatestamp.before(itemLastHarvest)) {
        log.info("Item " + item.getHandle() + " was harvested more recently than the last update time reporetd by the OAI server; skipping.");
        return;
      }
     
      // Otherwise, clear and re-import the metadata and bitstreams
        item.clearMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
        if (descMD.size() == 1)
          MDxwalk.ingest(ourContext, item, descMD.get(0));
        else
          MDxwalk.ingest(ourContext, item, descMD);

        // Import the actual bitstreams
        if (harvestRow.getHarvestType() == 3) {
          log.info("Running ORE ingest on: " + item.getHandle());
         
          Bundle[] allBundles = item.getBundles();
          for (Bundle bundle : allBundles) {
            item.removeBundle(bundle);
          }
          ORExwalk.ingest(ourContext, item, oreREM);
        }
       
        scrubMetadata(item);
      }
      else
        // NOTE: did not find, so we create (presumably, there will never be a case where an item already
        // exists in a harvest collection but does not have an OAI_id)
      {
        wi = WorkspaceItem.create(ourContext, targetCollection, false);
        item = wi.getItem();
       
        hi = HarvestedItem.create(ourContext, item.getID(), itemOaiID);
        //item.setOaiID(itemOaiID);
       
        if (descMD.size() == 1)
          MDxwalk.ingest(ourContext, item, descMD.get(0));
        else
          MDxwalk.ingest(ourContext, item, descMD);
       
        if (harvestRow.getHarvestType() == 3) {
          ORExwalk.ingest(ourContext, item, oreREM);
        }
       
        // see if we can do something about the wonky metadata
        scrubMetadata(item);
       
        // see if a handle can be exracted for the item
        String handle = extractHandle(item);
       
        if (handle != null)
        {
          DSpaceObject dso = HandleManager.resolveToObject(ourContext, handle);
          if (dso != null)
            throw new HarvestingException("Handle collision: attempted to re-assign handle '" + handle + "' to an incoming harvested item '" + hi.getOaiID() + "'.");                   
        }
       
        try {
          item = InstallItem.installItem(ourContext, wi, handle);
          //item = InstallItem.installItem(ourContext, wi);
        }
        // clean up the workspace item if something goes wrong before
        catch(SQLException se) {
          wi.deleteWrapper();
          throw se;
        }
        catch(IOException ioe) {
          wi.deleteWrapper();
          throw ioe;
        }
        catch(AuthorizeException ae) {
          wi.deleteWrapper();
          throw ae;
        }
      }
     
      // Now create the special ORE bundle and drop the ORE document in it
    if (harvestRow.getHarvestType() == 2 || harvestRow.getHarvestType() == 3)
    {
      Bundle OREBundle = item.createBundle("ORE");
     
      XMLOutputter outputter = new XMLOutputter();
      String OREString = outputter.outputString(oreREM);
      ByteArrayInputStream OREStream = new ByteArrayInputStream(OREString.getBytes());
     
      Bitstream OREBitstream = OREBundle.createBitstream(OREStream);
      OREBitstream.setName("ORE.xml");

      BitstreamFormat bf = FormatIdentifier.guessFormat(ourContext, OREBitstream);
      OREBitstream.setFormat(bf);
      OREBitstream.update();
     
      OREBundle.addBitstream(OREBitstream);
      OREBundle.update();
    }
   
    //item.setHarvestDate(new Date());
    hi.setHarvestDate(new Date());

                 // Add provenance that this item was harvested via OAI
                String provenanceMsg = "Item created via OAI harvest from source: "
                                        + this.harvestRow.getOaiSource() + " on " new DCDate(hi.getHarvestDate())
                                        + " (GMT).  Item's OAI Record identifier: " + hi.getOaiID();
                item.addMetadata("dc", "description", "provenance", "en", provenanceMsg);
       
    item.update();
    hi.update();
    long timeTaken = new Date().getTime() - timeStart.getTime();
    log.info("Item " + item.getHandle() + "(" + item.getID() + ")" + " has been ingested. The whole process took: " + timeTaken + " ms. ");

      // Un-ignore authorization
      ourContext.restoreAuthSystemState();
    }
View Full Code Here

            List<SyndEntry> entries = new ArrayList<SyndEntry>();
            for (DSpaceObject itemDSO : items)
            {
                if (itemDSO.getType() != Constants.ITEM)
                    continue;
                Item item = (Item)itemDSO;
                boolean hasDate = false;
                SyndEntry entry = new SyndEntryImpl();
                entries.add(entry);
            
                String entryURL = resolveURL(request, item);
                entry.setLink(entryURL);
                entry.setUri(entryURL);
            
                String title = getOneDC(item, titleField);
                entry.setTitle(title == null ? localize(labels, MSG_UNTITLED) : title);
            
                // "published" date -- should be dc.date.issued
                String pubDate = getOneDC(item, dateField);
                if (pubDate != null)
                {
                    entry.setPublishedDate((new DCDate(pubDate)).toDate());
                    hasDate = true;
                }
                // date of last change to Item
                entry.setUpdatedDate(item.getLastModified());
            
                StringBuffer db = new StringBuffer();
                for (String df : descriptionFields)
                {
                    // Special Case: "(date)" in field name means render as date
                    boolean isDate = df.indexOf("(date)") > 0;
                    if (isDate)
                        df = df.replaceAll("\\(date\\)", "");
            
                    DCValue dcv[] = item.getMetadata(df);
                    if (dcv.length > 0)
                    {
                        String fieldLabel = labels.get(MSG_METADATA + df);
                        if (fieldLabel != null && fieldLabel.length()>0)
                            db.append(fieldLabel + ": ");
                        boolean first = true;
                        for (DCValue v : dcv)
                        {
                            if (first)
                                first = false;
                            else
                                db.append("; ");
                            db.append(isDate ? new DCDate(v.value).toString() : v.value);
                        }
                        db.append("\n");
                    }
                }
                if (db.length() > 0)
                {
                    SyndContent desc = new SyndContentImpl();
                    desc.setType("text/plain");
                    desc.setValue(db.toString());
                    entry.setDescription(desc);
                }

                // This gets the authors into an ATOM feed
                DCValue authors[] = item.getMetadata(authorField);
                if (authors.length > 0)
                {
                    List<SyndPerson> creators = new ArrayList<SyndPerson>();
                    for (DCValue author : authors)
                    {
                        SyndPerson sp = new SyndPersonImpl();
                        sp.setName(author.value);
                        creators.add(sp);
                    }
                    entry.setAuthors(creators);
                }

                // only add DC module if any DC fields are configured
                if (dcCreatorField != null || dcDateField != null ||
                    dcDescriptionField != null)
                {
                    DCModule dc = new DCModuleImpl();
                    if (dcCreatorField != null)
                    {
                        DCValue dcAuthors[] = item.getMetadata(dcCreatorField);
                        if (dcAuthors.length > 0)
                        {
                            List<String> creators = new ArrayList<String>();
                            for (DCValue author : dcAuthors)
                                creators.add(author.value);
                            dc.setCreators(creators);
                        }
                    }
                    if (dcDateField != null && !hasDate)
                    {
                        DCValue v[] = item.getMetadata(dcDateField);
                        if (v.length > 0)
                            dc.setDate((new DCDate(v[0].value)).toDate());
                    }
                    if (dcDescriptionField != null)
                    {
                        DCValue v[] = item.getMetadata(dcDescriptionField);
                        if (v.length > 0)
                        {
                            StringBuffer descs = new StringBuffer();
                            for (DCValue d : v)
                            {
View Full Code Here

      /*
         * FYI: This method has to be scoped to a collection. Otherwise, we could have collisions as more
         * than one collection might be importing the same item. That is OAI_ID's might be unique to the
         * provider but not to the harvester.
         */
        Item resolvedItem = null;
        TableRowIterator tri = null;
        final String selectItemFromOaiId = "SELECT dsi.item_id FROM " +
          "(SELECT item.item_id, item.owning_collection FROM item JOIN harvested_item ON item.item_id=harvested_item.item_id WHERE harvested_item.oai_id=?) " +
          "dsi JOIN collection ON dsi.owning_collection=collection.collection_id WHERE collection.collection_id=?";
       
View Full Code Here

     *             if a db error occur
     */
    public static void authorizeManageBundlePolicy(Context context,
            Bundle bundle) throws AuthorizeException, SQLException
    {
        Item item = bundle.getItems()[0];
        authorizeManageItemPolicy(context, item);
    }
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.