public void setup(org.dspace.content.Bitstream bitstream, String expand) throws SQLException { List<String> expandFields = new ArrayList<String>(); if (expand != null) { expandFields = Arrays.asList(expand.split(",")); } // A logo bitstream might not have a bundle... if (bitstream.getBundles() != null & bitstream.getBundles().length >= 0) { if (bitstream.getParentObject().getType() == Constants.ITEM) { bundleName = bitstream.getBundles()[0].getName(); } } description = bitstream.getDescription(); format = bitstream.getFormatDescription(); sizeBytes = bitstream.getSize(); retrieveLink = "/bitstreams/" + bitstream.getID() + "/retrieve"; mimeType = bitstream.getFormat().getMIMEType(); sequenceId = bitstream.getSequenceID(); CheckSum checkSum = new CheckSum(); checkSum.setCheckSumAlgorith(bitstream.getChecksumAlgorithm()); checkSum.setValue(bitstream.getChecksum()); this.setCheckSum(checkSum); if (expandFields.contains("parent") || expandFields.contains("all")) { parentObject = new DSpaceObject(bitstream.getParentObject()); } else { this.addExpand("parent"); } if (!expandFields.contains("all")) { this.addExpand("all"); } }
/** * Remove a file from an item * * @param context current DSpace context * @param item Item where file should be removed from * @param bitstreamID The id of bitstream representing the file to remove * @return Status or error flag which will be processed by UI-related code! (if STATUS_COMPLETE or * 0 is returned, no errors occurred!) */ protected int processRemoveFile(Context context, Item item, int bitstreamID) throws IOException, SQLException, AuthorizeException { Bitstream bitstream; // Try to find bitstream try { bitstream = Bitstream.find(context, bitstreamID); } catch (NumberFormatException nfe) { bitstream = null; } if (bitstream == null) { // Invalid or mangled bitstream ID // throw an error and return immediately return STATUS_INTEGRITY_ERROR; } // remove bitstream from bundle.. // delete bundle if it's now empty Bundle[] bundles = bitstream.getBundles(); bundles[0].removeBitstream(bitstream); Bitstream[] bitstreams = bundles[0].getBitstreams(); // remove bundle if it's now empty if (bitstreams.length < 1) { item.removeBundle(bundles[0]); item.update(); } // no errors occurred return STATUS_COMPLETE; }
public static Document getRssDocument(Bitstream rssUrlBitstream) { try { return getRssDocument( rssUrlBitstream.getbContext(), rssUrlBitstream.retrieve(), rssUrlBitstream.getBundles()[0]); } catch (Exception e) { ExceptionLogger.logException(log, e); } return null; }
/** * Tests bitstream for membership in specified bundles (ORIGINAL, TEXT, THUMBNAIL) * * @param bitstream * @throws BitstreamFilterException * @returns true if bitstream is in specified bundles */ public boolean accept(Bitstream bitstream) throws BitstreamFilterException { try { Bundle[] bundles = bitstream.getBundles(); for (Bundle b : bundles) { for (String bn : bundlesToEmpty) { if (b.getName().equals(bn)) { return true; } } } } catch (SQLException e) { throw new BitstreamFilterException(e); } return false; }
/** * Delete bitstream from item * * @param context * @param ItemArchive * @param isTest * @param suppressUndo * @throws IllegalArgumentException * @throws ParseException * @throws IOException * @throws AuthorizeException * @throws SQLException */ public void execute(Context context, ItemArchive itarch, boolean isTest, boolean suppressUndo) throws IllegalArgumentException, IOException, SQLException, AuthorizeException, ParseException { File f = new File(itarch.getDirectory(), ItemUpdate.DELETE_CONTENTS_FILE); if (!f.exists()) { ItemUpdate.pr( "Warning: Delete_contents file for item " + itarch.getDirectoryName() + " not found."); } else { List<Integer> list = MetadataUtilities.readDeleteContentsFile(f); if (list.isEmpty()) { ItemUpdate.pr("Warning: empty delete_contents file for item " + itarch.getDirectoryName()); } else { for (int id : list) { try { Bitstream bs = Bitstream.find(context, id); if (bs == null) { ItemUpdate.pr("Bitstream not found by id: " + id); } else { Bundle[] bundles = bs.getBundles(); for (Bundle b : bundles) { if (isTest) { ItemUpdate.pr("Delete bitstream with id = " + id); } else { b.removeBitstream(bs); ItemUpdate.pr("Deleted bitstream with id = " + id); } } if (alterProvenance) { DtoMetadata dtom = DtoMetadata.create("dc.description.provenance", "en", ""); String append = "Bitstream " + bs.getName() + " deleted on " + DCDate.getCurrent() + "; "; Item item = bundles[0].getItems()[0]; ItemUpdate.pr("Append provenance with: " + append); if (!isTest) { MetadataUtilities.appendMetadata(item, dtom, false, append); } } } } catch (SQLException e) { ItemUpdate.pr("Error finding bitstream from id: " + id + " : " + e.toString()); } } } } }
/* If we created a new Bitstream but now realised there is a problem then remove it. */ private void backoutBitstream(SubmissionInfo subInfo, Bitstream b, Item item) throws SQLException, AuthorizeException, IOException { // remove bitstream from bundle.. // delete bundle if it's now empty Bundle[] bnd = b.getBundles(); bnd[0].removeBitstream(b); Bitstream[] bitstreams = bnd[0].getBitstreams(); // remove bundle if it's now empty if (bitstreams.length < 1) { item.removeBundle(bnd[0]); item.update(); } subInfo.setBitstream(null); }
/** * Check to see if the given user can perform the given action on the given object. Always returns * true if the ignore authorization flat is set in the current context. * * @param c current context. User is irrelevant; "ignore authorization" flag is relevant * @param o object action is being attempted on * @param action ID of action being attempted, from <code>org.dspace.core.Constants</code> * @param e user attempting action * @param useInheritance flag to say if ADMIN action on the current object or parent object can be * used * @return <code>true</code> if user is authorized to perform the given action, <code>false</code> * otherwise * @throws SQLException if database error */ protected boolean authorize( Context c, DSpaceObject o, int action, EPerson e, boolean useInheritance) throws SQLException { // return FALSE if there is no DSpaceObject if (o == null) { return false; } // is authorization disabled for this context? if (c.ignoreAuthorization()) { return true; } // is eperson set? if not, userToCheck = null (anonymous) EPerson userToCheck = null; if (e != null) { userToCheck = e; // perform isAdmin check to see // if user is an Admin on this object DSpaceObject adminObject = useInheritance ? serviceFactory.getDSpaceObjectService(o).getAdminObject(c, o, action) : null; if (isAdmin(c, adminObject)) { return true; } } // In case the dso is an bundle or bitstream we must ignore custom // policies if it does not belong to at least one installed item (see // DS-2614). // In case the dso is an item and a corresponding workspace or workflow // item exist, we have to ignore custom policies (see DS-2614). boolean ignoreCustomPolicies = false; if (o instanceof Bitstream) { Bitstream b = (Bitstream) o; // Ensure that this is not a collection or community logo DSpaceObject parent = bitstreamService.getParentObject(c, b); if (!(parent instanceof Collection) && !(parent instanceof Community)) { ignoreCustomPolicies = !isAnyItemInstalled(c, b.getBundles()); } } if (o instanceof Bundle) { ignoreCustomPolicies = !isAnyItemInstalled(c, Arrays.asList(((Bundle) o))); } if (o instanceof Item) { if (workspaceItemService.findByItem(c, (Item) o) != null || workflowItemService.findByItem(c, (Item) o) != null) { ignoreCustomPolicies = true; } } for (ResourcePolicy rp : getPoliciesActionFilter(c, o, action)) { if (ignoreCustomPolicies && ResourcePolicy.TYPE_CUSTOM.equals(rp.getRpType())) { continue; } // check policies for date validity if (resourcePolicyService.isDateValid(rp)) { if (rp.getEPerson() != null && rp.getEPerson().equals(userToCheck)) { return true; // match } if ((rp.getGroup() != null) && (groupService.isMember(c, rp.getGroup()))) { // group was set, and eperson is a member // of that group return true; } } } // default authorization is denial return false; }