/** delete the WorkflowItem, retaining the Item */
  public void deleteWrapper() throws SQLException, IOException, AuthorizeException {
    // Remove from cache
    ourContext.removeCached(this, getID());

    // delete any pending tasks
    WorkflowManager.deleteTasks(ourContext, this);

    // FIXME - auth?
    DatabaseManager.delete(ourContext, wfRow);
  }
Esempio n. 2
0
  /** Delete a group */
  public void delete() throws SQLException {
    // FIXME: authorizations

    myContext.addEvent(new Event(Event.DELETE, Constants.GROUP, getID(), getName()));

    // Remove from cache
    myContext.removeCached(this, getID());

    // Remove any ResourcePolicies that reference this group
    AuthorizeManager.removeGroupPolicies(myContext, getID());

    // Remove any group memberships first
    DatabaseManager.updateQuery(
        myContext, "DELETE FROM EPersonGroup2EPerson WHERE eperson_group_id= ? ", getID());

    // remove any group2groupcache entries
    DatabaseManager.updateQuery(
        myContext,
        "DELETE FROM group2groupcache WHERE parent_id= ? OR child_id= ? ",
        getID(),
        getID());

    // Now remove any group2group assignments
    DatabaseManager.updateQuery(
        myContext, "DELETE FROM group2group WHERE parent_id= ? OR child_id= ? ", getID(), getID());

    // don't forget the new table
    deleteEpersonGroup2WorkspaceItem();

    // Remove ourself
    DatabaseManager.delete(myContext, myRow);

    epeople.clear();

    log.info(LogManager.getHeader(myContext, "delete_group", "group_id=" + getID()));
  }
Esempio n. 3
0
  /**
   * Sends an email to the given e-person with details of new items in the given dspace object (MUST
   * be a community or a collection), items that appeared yesterday. No e-mail is sent if there
   * aren't any new items in any of the dspace objects.
   *
   * @param context DSpace context object
   * @param eperson eperson to send to
   * @param rpkeys List of DSpace Objects
   * @param test
   * @throws SearchServiceException
   */
  public static void sendEmail(
      Researcher researcher,
      Context context,
      EPerson eperson,
      List<String> rpkeys,
      boolean test,
      List<String> relationFields)
      throws IOException, MessagingException, SQLException, SearchServiceException {

    CrisSearchService searchService = researcher.getCrisSearchService();

    // Get a resource bundle according to the eperson language preferences
    Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);

    StringBuffer emailText = new StringBuffer();
    boolean isFirst = true;

    for (String rpkey : rpkeys) {
      SolrQuery query = new SolrQuery();
      query.setFields("search.resourceid");
      query.addFilterQuery(
          "{!field f=search.resourcetype}" + Constants.ITEM, "{!field f=inarchive}true");

      for (String tmpRelations : relationFields) {
        String fq = "{!field f=" + tmpRelations + "}" + rpkey;
        query.addFilterQuery(fq);
      }

      query.setRows(Integer.MAX_VALUE);

      if (ConfigurationManager.getBooleanProperty("eperson.subscription.onlynew", false)) {
        // get only the items archived yesterday
        query.setQuery("dateaccessioned:(NOW/DAY-1DAY)");
      } else {
        // get all item modified yesterday but not published the day
        // before
        // and all the item modified today and archived yesterday
        query.setQuery(
            "(item.lastmodified:(NOW/DAY-1DAY) AND dateaccessioned:(NOW/DAY-1DAY)) OR ((item.lastmodified:(NOW/DAY) AND dateaccessioned:(NOW/DAY-1DAY)))");
      }

      QueryResponse qResponse = searchService.search(query);
      SolrDocumentList results = qResponse.getResults();

      // Only add to buffer if there are new items
      if (results.getNumFound() > 0) {

        if (!isFirst) {
          emailText.append("\n---------------------------------------\n");
        } else {
          isFirst = false;
        }

        emailText
            .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.new-items", supportedLocale))
            .append(" ")
            .append(rpkey)
            .append(": ")
            .append(results.getNumFound())
            .append("\n\n");

        for (SolrDocument solrDoc : results) {

          Item item = Item.find(context, (Integer) solrDoc.getFieldValue("search.resourceid"));

          DCValue[] titles = item.getDC("title", null, Item.ANY);
          emailText
              .append("      ")
              .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.title", supportedLocale))
              .append(" ");

          if (titles.length > 0) {
            emailText.append(titles[0].value);
          } else {
            emailText.append(
                I18nUtil.getMessage("org.dspace.eperson.Subscribe.untitled", supportedLocale));
          }

          DCValue[] authors = item.getDC("contributor", Item.ANY, Item.ANY);

          if (authors.length > 0) {
            emailText
                .append("\n    ")
                .append(
                    I18nUtil.getMessage("org.dspace.eperson.Subscribe.authors", supportedLocale))
                .append(" ")
                .append(authors[0].value);

            for (int k = 1; k < authors.length; k++) {
              emailText.append("\n             ").append(authors[k].value);
            }
          }

          emailText
              .append("\n         ")
              .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.id", supportedLocale))
              .append(" ")
              .append(HandleManager.getCanonicalForm(item.getHandle()))
              .append("\n\n");
          context.removeCached(item, item.getID());
        }
      }
    }

    // Send an e-mail if there were any new items
    if (emailText.length() > 0) {

      if (test) {
        log.info(LogManager.getHeader(context, "subscription:", "eperson=" + eperson.getEmail()));
        log.info(LogManager.getHeader(context, "subscription:", "text=" + emailText.toString()));

      } else {

        Email email =
            ConfigurationManager.getEmail(
                I18nUtil.getEmailFilename(supportedLocale, "subscription"));
        email.addRecipient(eperson.getEmail());
        email.addArgument(emailText.toString());
        email.send();

        log.info(
            LogManager.getHeader(context, "sent_subscription", "eperson_id=" + eperson.getID()));
      }
    }
  }