@Override public void close() { if (isValid()) { abort(); } }
@Override protected void finalize() throws Throwable { /* * If a context is garbage-collected, we roll back and free up the * database connection if there is one. */ if (dbConnection != null && dbConnection.isTransActionAlive()) { abort(); } super.finalize(); }
private void closeContext(Context context) { if (context != null && context.isValid()) { context.abort(); } }
public static void abortContext(HttpServletRequest request) { Context context = (Context) request.getAttribute(DSPACE_CONTEXT); if (context != null && context.isValid()) { context.abort(); } }
/** * Abort all of the contexts held by this class. No changes will * be written to the database */ public void abort() { // abort both contexts if (context != null && context.isValid()) { context.abort(); } if (authenticatorContext != null && authenticatorContext.isValid()) { authenticatorContext.abort(); } }
/** * Abort all of the contexts held by this class. No changes will * be written to the database */ public void abort() { // abort both contexts if (context != null && context.isValid()) { context.abort(); } if (authenticatorContext != null && authenticatorContext.isValid()) { authenticatorContext.abort(); } }
/** * Process finally statement. It will print message to logger error stream * and abort DSpace context, if was not properly ended. * * @param context Context which must be aborted. * @throws WebApplicationException This exception is thrown for user of REST API. */ protected void processFinally(org.dspace.core.Context context) throws WebApplicationException { if ((context != null) && (context.isValid())) { context.abort(); log.error("Something get wrong. Aborting context in finally statement."); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } }
/** * Process exception, print message to logger error stream and abort DSpace * context. * * @param message Message, which will be printed to error stream. * @param context Context which must be aborted. * @throws WebApplicationException This exception is throw for user of REST api. */ protected static void processException(String message, org.dspace.core.Context context) throws WebApplicationException { if ((context != null) && (context.isValid())) { context.abort(); } log.error(message); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); }
/** * Abort all of the contexts held by this class. No changes will * be written to the database */ public void abort() { // abort both contexts if (context != null && context.isValid()) { context.abort(); } if (authenticatorContext != null && authenticatorContext.isValid()) { authenticatorContext.abort(); } }
/** * List accounts having no password salt. * * @throws SQLException if database error */ private static void findUnsalted() throws SQLException { Context myContext = new Context(); List<EPerson> ePersons = ePersonService.findUnsalted(myContext); for (EPerson ePerson : ePersons) { System.out.println(ePerson.getEmail()); } myContext.abort(); // No changes to commit } }
@Override public void destroyObject(String key, PooledObject<Dispatcher> pooledDispatcher) throws Exception { Context ctx = new Context(); try { Dispatcher dispatcher = pooledDispatcher.getObject(); for (Iterator ci = dispatcher.getConsumers() .iterator(); ci.hasNext(); ) { ConsumerProfile cp = (ConsumerProfile) ci.next(); if (cp != null) { cp.getConsumer().finish(ctx); } } } catch (Exception e) { ctx.abort(); throw e; } }
public static void main(String[] args) throws ParseException { Context c = null; try { c = new Context(); UpdateAuthorities UpdateAuthorities = new UpdateAuthorities(c); if (processArgs(args, UpdateAuthorities) == 0) { System.exit(0); } UpdateAuthorities.run(); } finally { if (c != null) { c.abort(); } } }
public static void main(String[] args) { // get a context from an anonymous user. // don't switch off authorization system! We'll export the converted // data into a triple store that provides a public sparql endpoint. // all exported rdf data can be read by anonymous users. // We won't change the database => read_only context will assure this. Context context = new Context(Context.Mode.READ_ONLY); RDFizer myself = null; myself = new RDFizer(); myself.overrideContext(context); myself.runCLI(args); // we don't change anything in the database, so abort the context. context.abort(); }
/** * Authenticate the given service document request. This extracts the appropriate * information from the request and forwards to the appropriate authentication * method * * @param auth authentication credentials * @return SWORD context * @throws DSpaceSwordException can be thrown by the internals of the DSpace SWORD implementation * @throws SwordError SWORD error per SWORD spec * @throws SwordAuthException thrown if unable to authenticate */ public SwordContext authenticate(AuthCredentials auth) throws DSpaceSwordException, SwordError, SwordAuthException { Context context = this.constructContext(); SwordContext sc; try { sc = this.authenticate(context, auth); } catch (DSpaceSwordException | SwordError | RuntimeException | SwordAuthException e) { if (context != null && context.isValid()) { context.abort(); } throw e; } return sc; }
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(); } } }
/** * Authenticate the deposit request. * * @param deposit deposit request * @return a SWORDContext object containing the relevant users * @throws SWORDException passed through. * @throws SWORDErrorException on generic SWORD exception * @throws SWORDAuthenticationException Thrown if the authentication fails */ public SWORDContext authenticate(Deposit deposit) throws SWORDException, SWORDErrorException, SWORDAuthenticationException { Context context = this.constructContext(deposit.getIPAddress()); SWORDContext sc = null; try { sc = this.authenticate(context, deposit); } catch (SWORDException | SWORDErrorException | RuntimeException | SWORDAuthenticationException e) { if (context != null && context.isValid()) { context.abort(); } throw e; } return sc; }
/** * Commit the primary context held by this class, and abort the authenticated * user's context if it is different. This ensures that only changes written * through the appropriate user's context is persisted, and all other * operations are flushed. You should, in general, not try to commit the contexts directly * when using the SWORD API. * * @throws DSpaceSWORDException on database error. */ public void commit() throws DSpaceSWORDException { try { // commit the primary context if (context != null && context.isValid()) { context.complete(); } // the secondary context is for filtering permissions by only, and is // never committed, so we abort here if (authenticatorContext != null && authenticatorContext.isValid()) { authenticatorContext.abort(); } } catch (SQLException e) { throw new DSpaceSWORDException(e); } } }
/** * Authenticate the given ATOM document request. This extracts the * appropriate information from the request, and forwards to the * appropriate authentication method. * * @param request ATOM document request * @return a SWORDContext object containing the relevant users * @throws SWORDException passed through. * @throws SWORDErrorException on generic SWORD exception * @throws SWORDAuthenticationException Thrown if the authentication fails */ public SWORDContext authenticate(AtomDocumentRequest request) throws SWORDException, SWORDErrorException, SWORDAuthenticationException { Context context = this.constructContext(request.getIPAddress()); SWORDContext sc = null; try { sc = this.authenticate(context, request); } catch (SWORDException | SWORDErrorException | SWORDAuthenticationException | RuntimeException e) { if (context != null && context.isValid()) { context.abort(); } throw e; } return sc; }
/** * 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(); }
public void initializeSiteObject() { // After every migrate, ensure default Site is 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 if (siteService.findSite(context) == null) { siteService.createSite(context); } context.restoreAuthSystemState(); // Commit changes and close context context.complete(); } catch (Exception e) { log.error("Error attempting to add/update default DSpace Groups", e); } finally { // Clean up our context, if it still exists & it was never completed if (context != null && context.isValid()) { context.abort(); } } }