/** * 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; }
/** * 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; }