/**
   * 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;
  }
Beispiel #2
0
  /**
   * Deposits all the items excluding the specified IDs.
   *
   * @param ids Item IDs not to deposit.
   * @return Whether or not the deposit was successful.
   * @author Ampzz
   */
  public boolean depositAllExcept(int... ids) {

    if (!isOpen()) return false;

    Item[] allItems = botEnv.inventory.getItems();
    if (allItems.length == 0) return false;

    ArrayList<Item> possItems = new ArrayList<Item>();

    for (Item iItem : allItems) {
      boolean add = true;

      for (int id : ids) {
        if (iItem.getID() == id) add = false;
      }

      if (possItems.size() > 0 && add) {
        for (Item kItem : possItems) {
          if (kItem.getID() == iItem.getID()) add = false;
        }
      }

      if (add) possItems.add(iItem);
    }

    if (possItems.size() == 0) return true;

    for (Item jItem : possItems) {
      jItem.doAction("Deposit-all");
      sleep(300, 700);
    }

    return true;
  }
  /**
   * 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;
  }
  /**
   * *
   *
   * @return true si la {@link #itemDoublon} et {@link #itemRef} sont les meme
   */
  public boolean isOriginal() {

    if (itemDoublon.getID().equals(itemRef.getID())) {
      return true;
    } else {
      return false;
    }
  }
 public static boolean removeMapping(Item item, Category c) throws SQLException {
   final String sql =
       "delete from "
           + TABLE_NAME
           + " where "
           + ITEM_ID_FIELD_NAME
           + " = ? AND "
           + CATEGORY_ID_FIELD_NAME
           + " = ?;";
   final PreparedStatement st = DataManager.getCon().prepareStatement(sql);
   final int res;
   try {
     st.setLong(1, item.getID());
     st.setLong(2, c.getID());
     try {
       res = st.executeUpdate();
     } catch (MySQLIntegrityConstraintViolationException s) {
       return false;
     }
   } finally {
     try {
       if (st != null) {
         st.close();
       }
     } catch (final SQLException e) {
       System.out.println("Error closing prepared statement : " + e.getMessage());
     }
   }
   return res == 1;
 }
 public static boolean addMapping(Item item, Category c) throws SQLException {
   final String sql =
       "insert into "
           + TABLE_NAME
           + " ("
           + ITEM_ID_FIELD_NAME
           + ", "
           + CATEGORY_ID_FIELD_NAME
           + ") values (?, ?);";
   final PreparedStatement st =
       DataManager.getCon().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
   st.setQueryTimeout(5);
   final int res;
   try {
     st.setLong(1, item.getID());
     st.setLong(2, c.getID());
     try {
       res = st.executeUpdate();
     } catch (MySQLIntegrityConstraintViolationException s) {
       return false;
     }
   } finally {
     try {
       if (st != null) {
         st.close();
       }
     } catch (final SQLException e) {
       System.out.println("Error closing prepared statement : " + e.getMessage());
     }
   }
   return res == 1;
 }
Beispiel #7
0
 /**
  * Checks how many of the specified item the bank contains.
  *
  * @param itemID ID of the item to count.
  * @return itemAmount Stack size of item in bank.
  */
 public int getCount(int itemID) {
   if (!isOpen()) return 0;
   for (Item item : getItems()) {
     if (item == null) continue;
     if (item.getID() == itemID) return item.getStackSize();
   }
   return 0;
 }
Beispiel #8
0
 public void linkAlbum(Item a_Item) {
   // link album
   int id = a_Item.getID();
   Album child;
   for (int j = 0; j < getChildCount(); j++) {
     child = (Album) getChild(j);
     if (child.m_ID == id) {
       a_Item.setLinkedAlbum(child);
       j = getChildCount();
     }
   }
 }
Beispiel #9
0
 /**
  * Gets the Item for a specified item ID.
  *
  * @param itemID Item ID to look for.
  * @return Object of type Item with the specified ID.
  */
 public Item getItem(int itemID) {
   if (!isOpen()) return null;
   for (Item item : getItems()) {
     if (item == null) {
       continue;
     }
     if (item.getID() == itemID) {
       return item;
     }
   }
   return null;
 }
  /**
   * 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;
  }
Beispiel #11
0
 /**
  * Checks if the bank contains any of the given items identified by their IDs.
  *
  * @param IDs The item IDs to check for.
  * @return True if any of the specified items are found.
  */
 public boolean contains(int... IDs) {
   Item[] items = getItems();
   for (Item item : items) {
     if (item != null) {
       for (int ID : IDs) {
         if (item.getID() == ID) {
           return true;
         }
       }
     }
   }
   return false;
 }
Beispiel #12
0
 /**
  * Deposits all of the specified item in the inventory.
  *
  * @param itemID Name of item to be deposited.
  * @return Whether or not the items were deposited.
  */
 public boolean depositAll(int itemID) {
   if (!isOpen() || botEnv.inventory.getItems().length == 0) {
     return false;
   }
   int count = 0;
   for (Item it : botEnv.inventory.getItems()) {
     if (it.getID() == itemID) {
       count++;
       it.doAction("Deposit-all");
       sleep(100, 200);
     }
     if (botEnv.inventory.getCount(false, itemID) == 0) {
       break;
     }
   }
   return count != 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;
  }
Beispiel #14
0
  public void replaceUpload(UploadFile a_Uf, JSONValue a_Return) {
    m_AllUploads.remove(a_Uf);

    JSONObject jo = a_Return.isObject();

    if (jo != null) {
      Item item = new Item(this, jo, m_Container);
      m_IDtoItem.put(item.getID(), item);
      m_Items.add(item);

      if (m_View.getCurrentAlbum() == this) {
        m_View.replaceInView(a_Uf, item);
      }
    } else {
      if (m_View.getCurrentAlbum() == this) {
        m_View.removeFromView(a_Uf);
      }
    }
  }
Beispiel #15
0
  /** rearranges the albums */
  public void rearrangeTo(JSONArray a_Ids, Item m_CompareTo, boolean m_Before) {
    Loading.getInstance().loading("Re-arranging..");
    String bora = m_Before ? "before" : "after";

    m_Container.doJSONRequest(
        G3Viewer.REARRANGE_URL
            + m_CompareTo.getID()
            + "/"
            + bora
            + "?sourceids="
            + a_Ids.toString(),
        new HttpSuccessHandler() {

          @Override
          public void success(JSONValue aValue) {
            m_View.getCurrentAlbum().select();
          }
        },
        true,
        true);
  }
  @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;
  }
  /**
   * 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()));
    }
  }
Beispiel #19
0
 /**
  * Gets an item array of all the bank items.
  *
  * @return Array of bank items.
  */
 public Item[] getItems() {
   Interfaces interfaces = botEnv.interfaces;
   Interface inventoryInterface = interfaces.getInterface(BANK_INTERFACE_ID);
   if (inventoryInterface == null) {
     return new Item[0];
   }
   IComponent inventoryPane = inventoryInterface.getComponent(BANK_ITEM_PANE_ID);
   IComponent[] children = inventoryPane.getChildren();
   if (children == null || children.length == 0) {
     return new Item[0];
   }
   List<Item> items = new ArrayList<Item>();
   for (IComponent aChildren : children) {
     if (aChildren == null) {
       continue;
     }
     Item item = new Item(botEnv, aChildren);
     if (item.getID() == -1) {
       continue;
     }
     items.add(item);
   }
   return items.toArray(new Item[items.size()]);
 }