/**
   * Perform a database query to obtain the string array of values corresponding to the passed
   * parameters. This is only really called from <code>
   * getMetadata(schema, element, qualifier, lang);
   * </code> which will obtain the value from cache if available first.
   *
   * @param schema
   * @param element
   * @param qualifier
   * @param lang
   */
  @Override
  public List<DCValue> getMetadata(
      Item item, String schema, String element, String qualifier, String lang) {
    List<DCValue> metadata = new ArrayList<DCValue>();
    try {
      TableRowIterator tri;

      if (qualifier == null) {
        Object[] params = {item.getID(), element, schema};
        tri = DatabaseManager.query(context, getByMetadataElement, params);
      } else if (Item.ANY.equals(qualifier)) {
        Object[] params = {item.getID(), element, schema};
        tri = DatabaseManager.query(context, getByMetadataAnyQualifier, params);
      } else {
        Object[] params = {item.getID(), element, qualifier, schema};
        tri = DatabaseManager.query(context, getByMetadata, params);
      }

      while (tri.hasNext()) {
        TableRow tr = tri.next();
        DCValue dcv = new DCValue();
        dcv.schema = schema;
        dcv.element = element;
        dcv.qualifier = qualifier;
        dcv.language = lang;
        dcv.value = tr.getStringColumn("text_value");
        metadata.add(dcv);
      }
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
    return metadata;
  }
Exemplo n.º 2
0
  /**
   * See which items are possible to get the backup file from cloud.
   *
   * @param context DSpace context
   * @param item iterator of items
   * @return integer set with all the IDs Items that are possible to get the backup file from cloud
   */
  public Set<Integer> checkPossibleItemsGet(Context context, ItemIterator items) {
    // This will contain all the Items IDs that backup files could be get from cloud
    Set<Integer> setInfo = new HashSet<Integer>();

    try {
      // if exist some item to evaluate make the connection and
      // get items backups files in cloud
      if (items.hasNext() == true) {
        this.makeConnection();
        this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.ITEM));
      }

      // do the operation for all items
      while (items.hasNext() == true) {
        Item objItem = items.next();
        // check if it is possible and necessary to get a backup file from cloud
        Boolean checkCorrect = this.couldGetFileFromCloud(context, objItem.getID(), Constants.ITEM);
        // add the ID collection to set if correct
        if (checkCorrect == true) setInfo.add(objItem.getID());
      }

      // close the connection to cloud
      this.closeConnection();

    } catch (SQLException ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
    }

    return setInfo;
  }
  /**
   * Commit the contained item to the main archive. The item is associated with the relevant
   * collection, added to the search index, and any other tasks such as assigning dates are
   * performed.
   *
   * @return the fully archived item.
   */
  @Override
  public Item archive(Context context, BasicWorkflowItem workflowItem)
      throws SQLException, IOException, AuthorizeException {
    // FIXME: Check auth
    Item item = workflowItem.getItem();
    Collection collection = workflowItem.getCollection();

    log.info(
        LogManager.getHeader(
            context,
            "archive_item",
            "workflow_item_id="
                + workflowItem.getID()
                + "item_id="
                + item.getID()
                + "collection_id="
                + collection.getID()));

    installItemService.installItem(context, workflowItem);

    // Log the event
    log.info(
        LogManager.getHeader(
            context,
            "install_item",
            "workflow_id=" + workflowItem.getID() + ", item_id=" + item.getID() + "handle=FIXME"));

    return item;
  }
  /**
   * Commit the contained item to the main archive. The item is associated with the relevant
   * collection, added to the search index, and any other tasks such as assigning dates are
   * performed.
   *
   * @return the fully archived item.
   */
  private static Item archive(Context c, WorkflowItem wfi)
      throws SQLException, IOException, AuthorizeException {
    // FIXME: Check auth
    Item item = wfi.getItem();
    Collection collection = wfi.getCollection();

    log.info(
        LogManager.getHeader(
            c,
            "archive_item",
            "workflow_item_id="
                + wfi.getID()
                + "item_id="
                + item.getID()
                + "collection_id="
                + collection.getID()));

    InstallItem.installItem(c, wfi);

    // Log the event
    log.info(
        LogManager.getHeader(
            c,
            "install_item",
            "workflow_id=" + wfi.getID() + ", item_id=" + item.getID() + "handle=FIXME"));

    return item;
  }
  /**
   * Return the workflow item to the workspace of the submitter. The workflow item is removed, and a
   * workspace item created.
   *
   * @param c Context
   * @param wfi WorkflowItem to be 'dismantled'
   * @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);
    wi.setMultipleFiles(wfi.hasMultipleFiles());
    wi.setMultipleTitles(wfi.hasMultipleTitles());
    wi.setPublishedBefore(wfi.isPublishedBefore());
    wi.update();

    // myitem.update();
    log.info(
        LogManager.getHeader(
            c,
            "return_to_workspace",
            "workflow_item_id=" + wfi.getID() + "workspace_item_id=" + wi.getID()));

    // Now remove the workflow object manually from the database
    DatabaseManager.updateQuery(c, "DELETE FROM WorkflowItem WHERE workflow_id=" + wfi.getID());

    return wi;
  }
Exemplo n.º 6
0
 /**
  * Return pathname element to this Item. Use db-id format if no handle, otherwise the DSpace
  * object format.
  *
  * @param item the item
  * @return the path elt
  */
 protected static String getPathElt(Item item) {
   String handle = item.getHandle();
   if (handle == null) {
     return getPathElt(item.getID());
   } else {
     return DAVDSpaceObject.getPathElt(item);
   }
 }
  @Override
  public void update(Item item) throws AuthorizeException {
    try {
      TableRow row = DatabaseManager.find(context, "item", item.getID());

      if (row != null) {
        // Fill out the TableRow and save it
        populateTableRowFromItem(item, row);
        row.setColumn("last_modified", new Date());
        row.setColumn("uuid", item.getIdentifier().getUUID().toString());
        DatabaseManager.update(context, row);
      } else {
        throw new RuntimeException("Didn't find item " + item.getID());
      }
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
 @Override
 public Version getVersion(VersionHistory versionHistory, Item item) {
   List<Version> versions = versionHistory.getVersions();
   for (Version v : versions) {
     if (v.getItem().getID() == item.getID()) {
       return v;
     }
   }
   return null;
 }
  /**
   * @param args
   * @throws SQLException
   * @throws IOException
   * @throws AuthorizeException
   */
  public static void main(String[] args) throws SQLException, AuthorizeException, IOException {

    Context ctx = new Context();
    ctx.setIgnoreAuthorization(true);
    ItemIterator iter = Item.findAll(ctx);

    Properties props = new Properties();

    File processed = new File("license.processed");

    if (processed.exists()) props.load(new FileInputStream(processed));

    int i = 0;

    try {
      while (iter.hasNext()) {
        if (i == 100) {
          props.store(
              new FileOutputStream(processed),
              "processed license files, remove to restart processing from scratch");
          i = 0;
        }

        Item item = (Item) iter.next();
        log.info("checking: " + item.getID());
        if (!props.containsKey("I" + item.getID())) {
          handleItem(item);
          log.info("processed: " + item.getID());
        }

        item.decache();
        props.put("I" + item.getID(), "done");
        i++;
      }

    } finally {
      props.store(
          new FileOutputStream(processed),
          "processed license files, remove to restart processing from scratch");
    }
  }
Exemplo n.º 10
0
  /**
   * Commit the contained item to the main archive. The item is associated with the relevant
   * collection, added to the search index, and any other tasks such as assigning dates are
   * performed.
   *
   * @param context The relevant DSpace Context.
   * @param wfi workflow item
   * @return the fully archived item.
   * @throws IOException A general class of exceptions produced by failed or interrupted I/O
   *     operations.
   * @throws SQLException An exception that provides information on a database access error or other
   *     errors.
   * @throws AuthorizeException Exception indicating the current user of the context does not have
   *     permission to perform a particular action.
   */
  @Override
  public Item archive(Context context, XmlWorkflowItem wfi)
      throws SQLException, IOException, AuthorizeException {
    // FIXME: Check auth
    Item item = wfi.getItem();
    Collection collection = wfi.getCollection();

    // Remove (if any) the workflowItemroles for this item
    workflowItemRoleService.deleteForWorkflowItem(context, wfi);

    log.info(
        LogManager.getHeader(
            context,
            "archive_item",
            "workflow_item_id="
                + wfi.getID()
                + "item_id="
                + item.getID()
                + "collection_id="
                + collection.getID()));

    installItemService.installItem(context, wfi);

    // Notify
    notifyOfArchive(context, item, collection);

    // Clear any remaining workflow metadata
    itemService.clearMetadata(
        context, item, WorkflowRequirementsService.WORKFLOW_SCHEMA, Item.ANY, Item.ANY, Item.ANY);
    itemService.update(context, item);

    // Log the event
    log.info(
        LogManager.getHeader(
            context,
            "install_item",
            "workflow_item_id=" + wfi.getID() + ", item_id=" + item.getID() + "handle=FIXME"));

    return item;
  }
Exemplo n.º 11
0
  /**
   * startWorkflow() begins a workflow - in a single transaction do away with the PersonalWorkspace
   * entry and turn it into a WorkflowItem.
   *
   * @param c Context
   * @param wsi The WorkspaceItem to convert to a workflow item
   * @return The resulting workflow item
   */
  public static WorkflowItem start(Context c, WorkspaceItem wsi)
      throws SQLException, AuthorizeException, IOException {
    // FIXME Check auth
    Item myitem = wsi.getItem();
    Collection collection = wsi.getCollection();

    log.info(
        LogManager.getHeader(
            c,
            "start_workflow",
            "workspace_item_id="
                + wsi.getID()
                + "item_id="
                + myitem.getID()
                + "collection_id="
                + collection.getID()));

    // record the start of the workflow w/provenance message
    recordStart(c, myitem);

    // create the WorkflowItem
    TableRow row = DatabaseManager.create(c, "workflowitem");
    row.setColumn("item_id", myitem.getID());
    row.setColumn("collection_id", wsi.getCollection().getID());

    WorkflowItem wfi = new WorkflowItem(c, row);

    wfi.setMultipleFiles(wsi.hasMultipleFiles());
    wfi.setMultipleTitles(wsi.hasMultipleTitles());
    wfi.setPublishedBefore(wsi.isPublishedBefore());

    // remove the WorkspaceItem
    wsi.deleteWrapper();

    // now get the worflow started
    doState(c, wfi, WFSTATE_STEP1POOL, null);

    // Return the workflow item
    return wfi;
  }
Exemplo n.º 12
0
 /**
  * Is the given item in a DSpace workspace?
  *
  * <p>This method queries the database directly to determine if this is the case rather than using
  * the DSpace API (which is very slow)
  *
  * @param context
  * @param item
  * @return
  * @throws DSpaceSwordException
  */
 public boolean isItemInWorkspace(Context context, Item item) throws DSpaceSwordException {
   try {
     String query = "SELECT workspace_item_id FROM workspaceitem WHERE item_id = ?";
     Object[] params = {item.getID()};
     TableRowIterator tri = DatabaseManager.query(context, query, params);
     if (tri.hasNext()) {
       tri.close();
       return true;
     }
     return false;
   } catch (SQLException e) {
     throw new DSpaceSwordException(e);
   }
 }
 @Override
 public void unlink(Collection collection, Item item) throws AuthorizeException {
   if (linked(collection, item)) {
     try {
       DatabaseManager.updateQuery(
           context,
           "DELETE FROM collection2item WHERE collection_id= ? " + "AND item_id= ? ",
           collection.getID(),
           item.getID());
     } catch (SQLException sqle) {
       throw new RuntimeException(sqle);
     }
   }
 }
  @Override
  public void link(Collection collection, Item item) throws AuthorizeException {
    if (!linked(collection, item)) {
      try {
        TableRow row = DatabaseManager.create(context, "collection2item");

        row.setColumn("collection_id", collection.getID());
        row.setColumn("item_id", item.getID());

        DatabaseManager.update(context, row);
      } catch (SQLException sqle) {
        throw new RuntimeException(sqle);
      }
    }
  }
  @Override
  public List<Collection> getParentCollections(Item item) {
    try {
      TableRowIterator tri =
          DatabaseManager.queryTable(
              context,
              "collection",
              "SELECT collection_id " + "FROM collection2item " + "WHERE item_id = ? ",
              item.getID());

      return returnAsList(tri);
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemplo n.º 16
0
  /**
   * Look up the id of the template item for a given collection.
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @return The id of the template item.
   * @throws IOException
   */
  public static int getTemplateItemID(Context context, int collectionID)
      throws SQLException, AuthorizeException, IOException {
    Collection collection = Collection.find(context, collectionID);
    Item template = collection.getTemplateItem();

    if (template == null) {
      collection.createTemplateItem();
      template = collection.getTemplateItem();

      collection.update();
      template.update();
      context.commit();
    }

    return template.getID();
  }
  private void populateTableRowFromCollection(Collection collection, TableRow row) {
    int id = collection.getID();
    Bitstream logo = collection.getLogo();
    Item templateItem = collection.getTemplateItem();
    Group admins = collection.getAdministrators();
    Group[] workflowGroups = collection.getWorkflowGroups();

    if (logo == null) {
      row.setColumnNull("logo_bitstream_id");
    } else {
      row.setColumn("logo_bitstream_id", logo.getID());
    }

    if (templateItem == null) {
      row.setColumnNull("template_item_id");
    } else {
      row.setColumn("template_item_id", templateItem.getID());
    }

    if (admins == null) {
      row.setColumnNull("admin");
    } else {
      row.setColumn("admin", admins.getID());
    }

    for (int i = 1; i <= workflowGroups.length; i++) {
      Group g = workflowGroups[i - 1];
      if (g == null) {
        row.setColumnNull("workflow_step_" + i);
      } else {
        row.setColumn("workflow_step_" + i, g.getID());
      }
    }

    // Now loop over all allowed metadata fields and set the value into the
    // TableRow.
    for (CollectionMetadataField field : CollectionMetadataField.values()) {
      String value = collection.getMetadata(field.toString());
      if (value == null) {
        row.setColumnNull(field.toString());
      } else {
        row.setColumn(field.toString(), value);
      }
    }

    row.setColumn("uuid", collection.getIdentifier().getUUID().toString());
  }
Exemplo n.º 18
0
  private void populateTableRowFromItem(Item item, TableRow row) {
    EPerson submitter = item.getSubmitter();
    Collection owningCollection = item.getOwningCollection();

    row.setColumn("item_id", item.getID());
    row.setColumn("in_archive", item.isArchived());
    row.setColumn("withdrawn", item.isWithdrawn());
    row.setColumn("last_modified", item.getLastModified());

    if (submitter != null) {
      row.setColumn("submitter_id", submitter.getID());
    }

    if (owningCollection != null) {
      row.setColumn("owning_collection", owningCollection.getID());
    }
  }
Exemplo n.º 19
0
  @Override
  public void unlink(Item item, Bundle bundle) throws AuthorizeException {
    if (!linked(item, bundle)) {
      return;
    }

    try {
      // Remove bundle mappings from DB
      DatabaseManager.updateQuery(
          context,
          "DELETE FROM item2bundle WHERE item_id= ? " + "AND bundle_id= ? ",
          item.getID(),
          bundle.getID());
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemplo n.º 20
0
 /**
  * Obtain the WorkflowItem object which wraps the given Item
  *
  * <p>This method queries the database directly to determine if this is the case rather than using
  * the DSpace API (which is very slow)
  *
  * @param context
  * @param item
  * @return
  * @throws DSpaceSwordException
  */
 public WorkflowItem getWorkflowItem(Context context, Item item) throws DSpaceSwordException {
   try {
     String query = "SELECT workflow_id FROM workflowitem WHERE item_id = ?";
     Object[] params = {item.getID()};
     TableRowIterator tri = DatabaseManager.query(context, query, params);
     if (tri.hasNext()) {
       TableRow row = tri.next();
       int wfid = row.getIntColumn("workflow_id");
       WorkflowItem wfi = WorkflowItem.find(context, wfid);
       tri.close();
       return wfi;
     }
     return null;
   } catch (SQLException e) {
     throw new DSpaceSwordException(e);
   }
 }
Exemplo n.º 21
0
  @Override
  public void loadMetadata(Item item) {
    MetadataFieldDAO mfDAO = MetadataFieldDAOFactory.getInstance(context);
    MetadataSchemaDAO msDAO = MetadataSchemaDAOFactory.getInstance(context);

    try {
      TableRowIterator tri =
          DatabaseManager.queryTable(
              context,
              "metadatavalue",
              "SELECT * FROM MetadataValue "
                  + "WHERE item_id = ? "
                  + "ORDER BY metadata_field_id, place",
              item.getID());

      List<DCValue> metadata = new ArrayList<DCValue>();

      for (TableRow row : tri.toList()) {
        // Get the associated metadata field and schema information
        int fieldID = row.getIntColumn("metadata_field_id");
        MetadataField field = mfDAO.retrieve(fieldID);

        if (field == null) {
          log.error("Loading item - cannot find metadata field " + fieldID);
        } else {
          MetadataSchema schema = msDAO.retrieve(field.getSchemaID());

          // Make a DCValue object
          DCValue dcv = new DCValue();
          dcv.schema = schema.getName();
          dcv.element = field.getElement();
          dcv.qualifier = field.getQualifier();
          dcv.language = row.getStringColumn("text_lang");
          dcv.value = row.getStringColumn("text_value");

          // Add it to the item
          metadata.add(dcv);
        }
      }

      item.setMetadata(metadata);
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
  @Override
  public boolean linked(Collection collection, Item item) {
    try {
      TableRowIterator tri =
          DatabaseManager.query(
              context,
              "SELECT id FROM collection2item " + "WHERE collection_id = ? AND item_id = ? ",
              collection.getID(),
              item.getID());

      boolean result = tri.hasNext();
      tri.close();

      return result;
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemplo n.º 23
0
 /**
  * Returns canonical link to a bitstream in the item.
  *
  * @param item The DSpace Item that the bitstream is part of
  * @param bitstream The bitstream to link to
  * @returns a String link to the bitstream
  */
 private String makeBitstreamLink(Item item, Bitstream bitstream) {
   String name = bitstream.getName();
   StringBuilder result = new StringBuilder(contextPath);
   result.append("/bitstream/item/").append(String.valueOf(item.getID()));
   // append name although it isn't strictly necessary
   try {
     if (name != null) {
       result.append("/").append(Util.encodeBitstreamName(name, "UTF-8"));
     }
   } catch (UnsupportedEncodingException uee) {
     // just ignore it, we don't have to have a pretty
     // name on the end of the url because the sequence id will
     // locate it. However it means that links in this file might
     // not work....
   }
   result.append("?sequence=").append(String.valueOf(bitstream.getSequenceID()));
   return result.toString();
 }
Exemplo n.º 24
0
  /**
   * Send a collection backup file and respective children to cloud to be preserved.
   *
   * @param context context DSpace
   * @param ref ID of the collection
   * @param establishConnection true if pretend establish connection to cloud
   * @return true if file correctly sent to cloud, or false if not
   */
  public Boolean sendCollectionAndChilds(
      Context context, Integer ref, Boolean establishConnection) {
    // if first, make connection and get collection and item files preserved in cloud
    if (establishConnection == true) {
      this.makeConnection();
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.COLLECTION));
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.ITEM));
    }

    // send to cloud atual collection
    sendCollection(context, ref, false);

    Collection obj;
    ItemIterator items;

    // get the items presents in the collection
    try {
      obj = Collection.find(context, ref);
      items = obj.getAllItems();
    } catch (Exception ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      // it means it is the first father in the order, so close connection
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // send to cloud, one by one, each item
    try {
      if (items.hasNext()) {
        Item newObj = items.next();
        sendItem(context, newObj.getID(), false);
      }
    } catch (Exception ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      // it means it is the first father in the order, so close connection
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // it means it is the first father in the order
    if (establishConnection == true) this.closeConnection();

    return true;
  }
Exemplo n.º 25
0
  @Override
  public void link(Item item, Bundle bundle) throws AuthorizeException {
    if (linked(item, bundle)) {
      return;
    }

    try {
      TableRow row = DatabaseManager.create(context, "item2bundle");
      row.setColumn("item_id", item.getID());
      row.setColumn("bundle_id", bundle.getID());
      DatabaseManager.update(context, row);

      // If we're adding the Bundle to the Item, we bequeath our
      // policies unto it.
      AuthorizeManager.inheritPolicies(context, item, bundle);
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemplo n.º 26
0
  @Override
  public boolean linked(Item item, Bundle bundle) {
    try {
      TableRowIterator tri =
          DatabaseManager.query(
              context,
              "SELECT id FROM item2bundle "
                  + " WHERE item_id="
                  + item.getID()
                  + " AND bundle_id="
                  + bundle.getID());

      boolean result = tri.hasNext();
      tri.close();

      return result;
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemplo n.º 27
0
  /** notify the submitter that the item is archived */
  private static void notifyOfArchive(Context c, Item i, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = i.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email =
          ConfigurationManager.getEmail(
              I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = HandleManager.findHandle(c, i);

      // Get title
      DCValue[] titles = i.getDC("title", null, Item.ANY);
      String title = "";
      try {
        title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
      } catch (MissingResourceException e) {
        title = "Untitled";
      }
      if (titles.length > 0) {
        title = titles[0].value;
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getMetadata("name"));
      email.addArgument(HandleManager.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              c, "notifyOfArchive", "cannot email user" + " item_id=" + i.getID()));
    }
  }
  @Override
  public BasicWorkflowItem start(Context context, WorkspaceItem wsi)
      throws SQLException, AuthorizeException, IOException {
    // FIXME Check auth
    Item myitem = wsi.getItem();
    Collection collection = wsi.getCollection();

    log.info(
        LogManager.getHeader(
            context,
            "start_workflow",
            "workspace_item_id="
                + wsi.getID()
                + "item_id="
                + myitem.getID()
                + "collection_id="
                + collection.getID()));

    // record the start of the workflow w/provenance message
    recordStart(context, myitem);

    // create the WorkflowItem
    BasicWorkflowItem wfi = workflowItemService.create(context, myitem, collection);
    wfi.setMultipleFiles(wsi.hasMultipleFiles());
    wfi.setMultipleTitles(wsi.hasMultipleTitles());
    wfi.setPublishedBefore(wsi.isPublishedBefore());

    // remove the WorkspaceItem
    workspaceItemService.deleteWrapper(context, wsi);

    // now get the workflow started
    wfi.setState(WFSTATE_SUBMIT);
    advance(context, wfi, null);

    // Return the workflow item
    return wfi;
  }
Exemplo n.º 29
0
  /**
   * notify the submitter that the item is archived
   *
   * @param context The relevant DSpace Context.
   * @param item which item was archived
   * @param coll collection name to display in template
   * @throws SQLException An exception that provides information on a database access error or other
   *     errors.
   * @throws IOException A general class of exceptions produced by failed or interrupted I/O
   *     operations.
   */
  protected void notifyOfArchive(Context context, Item item, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = item.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = handleService.findHandle(context, item);

      // Get title
      List<MetadataValue> titles =
          itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
      String title = "";
      try {
        title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
      } catch (MissingResourceException e) {
        title = "Untitled";
      }
      if (titles.size() > 0) {
        title = titles.iterator().next().getValue();
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getName());
      email.addArgument(handleService.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              context, "notifyOfArchive", "cannot email user" + " item_id=" + item.getID()));
    }
  }
  /** notify the submitter that the item is archived */
  protected void notifyOfArchive(Context context, Item item, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = item.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = handleService.findHandle(context, item);

      // Get title
      String title = item.getName();
      if (StringUtils.isBlank(title)) {
        try {
          title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
        } catch (MissingResourceException e) {
          title = "Untitled";
        }
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getName());
      email.addArgument(handleService.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              context,
              "notifyOfArchive",
              "cannot email user; item_id=" + item.getID() + ":  " + e.getMessage()));
    }
  }