📄 collection.java
字号:
* effect. Setting a logo and not calling <code>update</code> later may * result in a previous logo lying around as an "orphaned" bitstream. * * @param is the stream to use as the new logo * * @return the new logo bitstream, or <code>null</code> if there is no * logo (<code>null</code> was passed in) * @throws AuthorizeException * @throws IOException * @throws SQLException */ public Bitstream setLogo(InputStream is) throws AuthorizeException, IOException, SQLException { // Check authorisation // authorized to remove the logo when DELETE rights // authorized when canEdit if (!((is == null) && AuthorizeManager.authorizeActionBoolean( ourContext, this, Constants.DELETE))) { canEdit(); } // First, delete any existing logo if (!collectionRow.isColumnNull("logo_bitstream_id")) { logo.delete(); } if (is == null) { collectionRow.setColumnNull("logo_bitstream_id"); logo = null; log.info(LogManager.getHeader(ourContext, "remove_logo", "collection_id=" + getID())); } else { Bitstream newLogo = Bitstream.create(ourContext, is); collectionRow.setColumn("logo_bitstream_id", newLogo.getID()); logo = newLogo; // now create policy for logo bitstream // to match our READ policy List policies = AuthorizeManager.getPoliciesActionFilter( ourContext, this, Constants.READ); AuthorizeManager.addPolicies(ourContext, policies, newLogo); log.info(LogManager.getHeader(ourContext, "set_logo", "collection_id=" + getID() + "logo_bitstream_id=" + newLogo.getID())); } return logo; } /** * Create a workflow group for the given step if one does not already exist. * Returns either the newly created group or the previously existing one. * Note that while the new group is created in the database, the association * between the group and the collection is not written until * <code>update</code> is called. * * @param step * the step (1-3) of the workflow to create or get the group for * * @return the workflow group associated with this collection * @throws SQLException * @throws AuthorizeException */ public Group createWorkflowGroup(int step) throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); if (workflowGroup[step - 1] == null) { Group g = Group.create(ourContext); g.setName("COLLECTION_" + getID() + "_WORKFLOW_STEP_" + step); g.update(); setWorkflowGroup(step, g); AuthorizeManager.addPolicy(ourContext, this, Constants.ADD, g); } return workflowGroup[step - 1]; } /** * Set the workflow group corresponding to a particular workflow step. * <code>null</code> can be passed in if there should be no associated * group for that workflow step; any existing group is NOT deleted. * * @param step * the workflow step (1-3) * @param g * the new workflow group, or <code>null</code> */ public void setWorkflowGroup(int step, Group g) { workflowGroup[step - 1] = g; if (g == null) { collectionRow.setColumnNull("workflow_step_" + step); } else { collectionRow.setColumn("workflow_step_" + step, g.getID()); } } /** * Get the the workflow group corresponding to a particular workflow step. * This returns <code>null</code> if there is no group associated with * this collection for the given step. * * @param step * the workflow step (1-3) * * @return the group of reviewers or <code>null</code> */ public Group getWorkflowGroup(int step) { return workflowGroup[step - 1]; } /** * Create a default submitters group if one does not already exist. Returns * either the newly created group or the previously existing one. Note that * other groups may also be allowed to submit to this collection by the * authorization system. * * @return the default group of submitters associated with this collection * @throws SQLException * @throws AuthorizeException */ public Group createSubmitters() throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); if (submitters == null) { submitters = Group.create(ourContext); submitters.setName("COLLECTION_" + getID() + "_SUBMIT"); submitters.update(); } // register this as the submitter group collectionRow.setColumn("submitter", submitters.getID()); AuthorizeManager.addPolicy(ourContext, this, Constants.ADD, submitters); return submitters; } /** * Get the default group of submitters, if there is one. Note that the * authorization system may allow others to submit to the collection, so * this is not necessarily a definitive list of potential submitters. * <P> * The default group of submitters for collection 100 is the one called * <code>collection_100_submit</code>. * * @return the default group of submitters, or <code>null</code> if there * is no default group. */ public Group getSubmitters() { return submitters; } /** * Create a default administrators group if one does not already exist. * Returns either the newly created group or the previously existing one. * Note that other groups may also be administrators. * * @return the default group of editors associated with this collection * @throws SQLException * @throws AuthorizeException */ public Group createAdministrators() throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); if (admins == null) { admins = Group.create(ourContext); admins.setName("COLLECTION_" + getID() + "_ADMIN"); admins.update(); } AuthorizeManager.addPolicy(ourContext, this, Constants.COLLECTION_ADMIN, admins); // register this as the admin group collectionRow.setColumn("admin", admins.getID()); // administrators also get ADD on the submitter group if (submitters != null) { AuthorizeManager.addPolicy(ourContext, submitters, Constants.ADD, admins); } return admins; } /** * Get the default group of administrators, if there is one. Note that the * authorization system may allow others to be administrators for the * collection. * <P> * The default group of administrators for collection 100 is the one called * <code>collection_100_admin</code>. * * @return group of administrators, or <code>null</code> if there is no * default group. */ public Group getAdministrators() { return admins; } /** * Get the license that users must grant before submitting to this * collection. If the collection does not have a specific license, the * site-wide default is returned. * * @return the license for this collection */ public String getLicense() { String license = collectionRow.getStringColumn("license"); if ((license == null) || license.equals("")) { // Fallback to site-wide default license = ConfigurationManager.getDefaultSubmissionLicense(); } return license; } /** * Find out if the collection has a custom license * * @return <code>true</code> if the collection has a custom license */ public boolean hasCustomLicense() { String license = collectionRow.getStringColumn("license"); return ((license != null) && !license.equals("")); } /** * Set the license for this collection. Passing in <code>null</code> means * that the site-wide default will be used. * * @param license * the license, or <code>null</code> */ public void setLicense(String license) { if (license == null) { collectionRow.setColumnNull("license"); } else { collectionRow.setColumn("license", license); } } /** * Get the template item for this collection. <code>null</code> is * returned if the collection does not have a template. Submission * mechanisms may copy this template to provide a convenient starting point * for a submission. * * @return the item template, or <code>null</code> */ public Item getTemplateItem() throws SQLException { return template; } /** * Create an empty template item for this collection. If one already exists, * no action is taken. Caution: Make sure you call <code>update</code> on * the collection after doing this, or the item will have been created but * the collection record will not refer to it. * * @throws SQLException * @throws AuthorizeException */ public void createTemplateItem() throws SQLException, AuthorizeException { // Check authorisation canEdit(); if (template == null) { template = Item.create(ourContext); collectionRow.setColumn("template_item_id", template.getID()); log.info(LogManager.getHeader(ourContext, "create_template_item", "collection_id=" + getID() + ",template_item_id=" + template.getID())); } } /** * Remove the template item for this collection, if there is one. Note that * since this has to remove the old template item ID from the collection * record in the database, the colletion record will be changed, including * any other changes made; in other words, this method does an * <code>update</code>. * * @throws SQLException * @throws AuthorizeException * @throws IOException */ public void removeTemplateItem() throws SQLException, AuthorizeException, IOException { // Check authorisation canEdit(); collectionRow.setColumnNull("template_item_id"); DatabaseManager.update(ourContext, collectionRow); if (template != null) { log.info(LogManager.getHeader(ourContext, "remove_template_item", "collection_id=" + getID() + ",template_item_id=" + template.getID())); template.delete(); template = null; } } /** * Add an item to the collection. This simply adds a relationship between * the item and the collection - it does nothing like set an issue date, * remove a personal workspace item etc. This has instant effect; * <code>update</code> need not be called. * * @param item * item to add * @throws SQLException * @throws AuthorizeException */ public void addItem(Item item) throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); log.info(LogManager.getHeader(ourContext, "add_item", "collection_id=" + getID() + ",item_id=" + item.getID())); // Create mapping TableRow row = DatabaseManager.create(ourContext, "collection2item"); row.setColumn("collection_id", getID()); row.setColumn("item_id", item.getID()); DatabaseManager.update(ourContext, row); } /** * Remove an item. If the item is then orphaned, it is deleted. * * @param item * item to remove * @throws SQLException * @throws AuthorizeException * @throws IOException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -