@Override public void end(Context ctx) throws Exception { if (itemsToProcess != null) { for (Item item : itemsToProcess) { ctx.turnOffAuthorisationSystem(); try { itemService.update(ctx, item); } finally { ctx.restoreAuthSystemState(); } } } itemsToProcess = null; }
public static void main(String[] args) { LOG.debug("Starting DOI organiser "); // setup Context Context context = new Context(); // Started from commandline, don't use the authentication system. context.turnOffAuthorisationSystem(); DOIOrganiser organiser = new DOIOrganiser(context, new DSpace().getSingletonService(DOIIdentifierProvider.class)); // run command line interface runCLI(context, organiser, args); try { context.complete(); } catch (SQLException sqle) { System.err.println("Cannot save changes to database: " + sqle.getMessage()); System.exit(-1); } }
@Override public void removeDsoGroupPolicies(Context context, DSpaceObject dso, Group group) throws SQLException, AuthorizeException { resourcePolicyDAO.deleteByDsoGroupPolicies(context, dso, group); context.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(dso).updateLastModified(context, dso); context.restoreAuthSystemState(); }
@Override public void removeDsoAndTypeNotEqualsToPolicies(Context c, DSpaceObject o, String type) throws SQLException, AuthorizeException { resourcePolicyDAO.deleteByDsoAndTypeNotEqualsTo(c, o, type); c.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(o).updateLastModified(c, o); c.restoreAuthSystemState(); }
@Override public void removePolicies(Context c, DSpaceObject o, String type) throws SQLException, AuthorizeException { resourcePolicyDAO.deleteByDsoAndType(c, o, type); c.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(o).updateLastModified(c, o); c.restoreAuthSystemState(); }
@Override public void removeAllPolicies(Context c, DSpaceObject o) throws SQLException, AuthorizeException { resourcePolicyDAO.deleteByDso(c, o); c.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(o).updateLastModified(c, o); c.restoreAuthSystemState(); }
@Override public void removeDsoEPersonPolicies(Context context, DSpaceObject dso, EPerson ePerson) throws SQLException, AuthorizeException { resourcePolicyDAO.deleteByDsoEPersonPolicies(context, dso, ePerson); context.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(dso).updateLastModified(context, dso); context.restoreAuthSystemState(); }
private void updateFileName(DBConnection dspaceDbConnection, Context c, Item item, String fName) throws Exception { try{ c.turnOffAuthorisationSystem() Bundle[] bundles = item.getBundles("ORIGINAL"); for (int i = 0; i < bundles.length; i++) { Bitstream[] bitstreams = bundles[i].getBitstreams(); for (int j = 0; j < bitstreams.length; j++) { bitstreams[j].setName(fileName); bitstreams[j].update(); log.info("file name change:" + fileName); } } c.commit(); } finally { c.restoreAuthSystemState() }
public void initGroups() { // After every migrate, ensure default Groups are setup correctly. Context context = null; try { context = new Context(); context.turnOffAuthorisationSystem(); // While it's not really a formal "registry", we need to ensure the // default, required Groups exist in the DSpace database groupService.initDefaultGroupNames(context); context.restoreAuthSystemState(); // Commit changes and close context context.complete(); } catch (Exception e) { log.error("Error attempting to add/update default DSpace Groups", e); throw new RuntimeException(e); } finally { // Clean up our context, if it still exists & it was never completed if (context != null && context.isValid()) { context.abort(); } } }
@Override public void removePolicies(Context c, DSpaceObject o, int actionId) throws SQLException, AuthorizeException { if (actionId == -1) { removeAllPolicies(c, o); } else { resourcePolicyDAO.deleteByDsoAndAction(c, o, actionId); c.turnOffAuthorisationSystem(); contentServiceFactory.getDSpaceObjectService(o).updateLastModified(c, o); c.restoreAuthSystemState(); } }
/** * Initialize the Duplicate Detector and trigger parsing and running the command * @param args Command Line arguments */ public static void main(String args[]) { log.debug("Starting Duplicate Detector"); DSpace dspace = new DSpace(); // get a context Context context = new Context(); context.setMode(Context.Mode.READ_ONLY); // turn off Auth context.turnOffAuthorisationSystem(); DuplicateDetector detector = new DuplicateDetector(); detector.runCLI(context, args, detector); context.restoreAuthSystemState(); context.abort(); }
protected Item createItem(Context context) throws SQLException, AuthorizeException { Item item = itemDAO.create(context, new Item()); // set discoverable to true (default) item.setDiscoverable(true); // Call update to give the item a last modified date. OK this isn't // amazingly efficient but creates don't happen that often. context.turnOffAuthorisationSystem(); update(context, item); context.restoreAuthSystemState(); context.addEvent(new Event(Event.CREATE, Constants.ITEM, item.getID(), null, getIdentifiers(context, item))); log.info(LogManager.getHeader(context, "create_item", "item_id=" + item.getID())); return item; }
@Override public void setEmbargo(Context context, Item item) throws SQLException, AuthorizeException { // if lift is null, we might be restoring an item from an AIP DCDate myLift = getEmbargoTermsAsDate(context, item); if (myLift == null) { if ((myLift = recoverEmbargoDate(item)) == null) { return; } } String slift = myLift.toString(); try { context.turnOffAuthorisationSystem(); itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY); itemService.addMetadata(context, item, lift_schema, lift_element, lift_qualifier, null, slift); log.info("Set embargo on Item " + item.getHandle() + ", expires on: " + slift); setter.setEmbargo(context, item); itemService.update(context, item); } finally { context.restoreAuthSystemState(); } }
/** * Delete an ResourcePolicy * * @param context context * @param resourcePolicy resource policy * @throws SQLException if database error * @throws AuthorizeException if authorization error */ @Override public void delete(Context context, ResourcePolicy resourcePolicy) throws SQLException, AuthorizeException { // FIXME: authorizations // Remove ourself resourcePolicyDAO.delete(context, resourcePolicy); context.turnOffAuthorisationSystem(); if (resourcePolicy.getdSpaceObject() != null) { //A policy for a DSpace Object has been modified, fire a modify event on the DSpace object contentServiceFactory.getDSpaceObjectService(resourcePolicy.getdSpaceObject()) .updateLastModified(context, resourcePolicy.getdSpaceObject()); } context.restoreAuthSystemState(); }
@Override public WorkspaceItem abort(Context c, XmlWorkflowItem wi, EPerson e) throws AuthorizeException, SQLException, IOException { if (!authorizeService.isAdmin(c)) { throw new AuthorizeException( "You must be an admin to abort a workflow"); } c.turnOffAuthorisationSystem(); //Restore permissions for the submitter // convert into personal workspace WorkspaceItem wsi = returnToWorkspace(c, wi); log.info(LogManager.getHeader(c, "abort_workflow", "workflow_item_id=" + wi.getID() + "item_id=" + wsi.getItem().getID() + "collection_id=" + wi.getCollection().getID() + "eperson_id=" + e.getID())); c.restoreAuthSystemState(); return wsi; }
@Override public void removeTemplateItem(Context context, Collection collection) throws SQLException, AuthorizeException, IOException { // Check authorisation AuthorizeUtil.authorizeManageTemplateItem(context, collection); Item template = collection.getTemplateItem(); if (template != null) { log.info(LogManager.getHeader(context, "remove_template_item", "collection_id=" + collection.getID() + ",template_item_id=" + template.getID())); // temporarily turn off auth system, we have already checked the permission on the top of the method // check it again will fail because we have already broken the relation between the collection and the item context.turnOffAuthorisationSystem(); collection.setTemplateItem(null); itemService.delete(context, template); context.restoreAuthSystemState(); } context.addEvent(new Event(Event.MODIFY, Constants.COLLECTION, collection.getID(), "remove_template_item", getIdentifiers(context, collection))); }
@Override public Group createWorkflowGroup(Context context, Collection collection, int step) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create Workflow Group AuthorizeUtil.authorizeManageWorkflowsGroup(context, collection); if (getWorkflowGroup(collection, step) == null) { //turn off authorization so that Collection Admins can create Collection Workflow Groups context.turnOffAuthorisationSystem(); Group g = groupService.create(context); context.restoreAuthSystemState(); groupService.setName(g, "COLLECTION_" + collection.getID() + "_WORKFLOW_STEP_" + step); groupService.update(context, g); setWorkflowGroup(context, collection, step, g); } return getWorkflowGroup(collection, step); }
@Override public Group createAdministrators(Context context, Community community) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create more Admins AuthorizeUtil.authorizeManageAdminGroup(context, community); Group admins = community.getAdministrators(); if (admins == null) { //turn off authorization so that Community Admins can create Sub-Community Admins context.turnOffAuthorisationSystem(); admins = groupService.create(context); context.restoreAuthSystemState(); groupService.setName(admins, "COMMUNITY_" + community.getID() + "_ADMIN"); groupService.update(context, admins); } authorizeService.addPolicy(context, community, Constants.ADMIN, admins); // register this as the admin group community.setAdmins(admins); return admins; }
@Override public Group createSubmitters(Context context, Collection collection) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create Submitters Group AuthorizeUtil.authorizeManageSubmittersGroup(context, collection); Group submitters = collection.getSubmitters(); if (submitters == null) { //turn off authorization so that Collection Admins can create Collection Submitters context.turnOffAuthorisationSystem(); submitters = groupService.create(context); context.restoreAuthSystemState(); groupService.setName(submitters, "COLLECTION_" + collection.getID() + "_SUBMIT"); groupService.update(context, submitters); } // register this as the submitter group collection.setSubmitters(submitters); authorizeService.addPolicy(context, collection, Constants.ADD, submitters); return submitters; }
@Override public Group createAdministrators(Context context, Collection collection) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create more Admins AuthorizeUtil.authorizeManageAdminGroup(context, collection); Group admins = collection.getAdministrators(); if (admins == null) { //turn off authorization so that Community Admins can create Collection Admins context.turnOffAuthorisationSystem(); admins = groupService.create(context); context.restoreAuthSystemState(); groupService.setName(admins, "COLLECTION_" + collection.getID() + "_ADMIN"); groupService.update(context, admins); } authorizeService.addPolicy(context, collection, Constants.ADMIN, admins); // register this as the admin group collection.setAdmins(admins); return admins; }