private static Context getAnonContext() { if (anonContext == null) { anonContext = new Context(); } return anonContext; }
@Override public Context getContext() throws ContextServiceException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest(); Object value = request.getAttribute(OAI_CONTEXT); if (value == null || !(value instanceof Context)) { request.setAttribute(OAI_CONTEXT, new Context()); } return (Context) request.getAttribute(OAI_CONTEXT); } }
/** * Construct the context object member variable of this class * using the passed IP address as part of the loggable * information * * @throws DSpaceSwordException can be thrown by the internals of the DSpace SWORD implementation */ private Context constructContext() throws DSpaceSwordException { Context context = new Context(); // Set the session ID and IP address context.setExtraLogInfo("session_id=0"); return context; }
/** * Construct the context object member variable of this class * using the passed IP address as part of the loggable * information * * @param ip the ip address of the incoming request * @throws org.purl.sword.base.SWORDException */ private Context constructContext(String ip) throws SWORDException { Context context = new Context(); // Set the session ID and IP address context.setExtraLogInfo("session_id=0:ip_addr=" + ip); return context; }
/** * Refresh the DSpace Context object in order to periodically release objects from memory * @throws IOException * @throws SolrServerException */ private void refreshContext() throws SolrServerException, IOException { if (context != null) { try { totalCache += numUncache + context.getCacheSize(); } catch (SQLException e) { log.warn(e.getMessage()); } } this.context = new Context(Context.Mode.READ_ONLY); lastItem = null; lastBitstream = null; numUncache = 0; }
/** * Returns the context object used in the current curation thread. * This is primarily a utility method to allow tasks access to the context when necessary. * <p> * If the context is null or not set, then this just returns * a brand new Context object representing an Anonymous User. * * @return curation thread's Context object (or a new, anonymous Context if no curation Context exists) * @throws SQLException An exception that provides information on a database access error or other errors. */ public static Context curationContext() throws SQLException { // Return curation context or new context if undefined/invalid Context curCtx = curationCtx.get(); if (curCtx == null || !curCtx.isValid()) { //Create a new context (represents an Anonymous User) curCtx = new Context(); //Save it to current execution thread curationCtx.set(curCtx); } return curCtx; }
/** * Record that this application is not running. */ public void deregister() { // Remove the database entry try { Context context = new Context(); webAppService.delete(context, webApp); context.complete(); } catch (SQLException e) { log.error("Failed to record shutdown in Webapp table.", e); } }
public SwordContext noAuthContext() throws DSpaceSwordException { SwordContext sc = new SwordContext(); Context context = new Context(); sc.setContext(context); return sc; }
/** * Record that this application is running. */ public void register() { // Create the database entry Timestamp now = new Timestamp(started.getTime()); try { Context context = new Context(); webApp = webAppService.create(context, kind, url, now, isUI() ? 1 : 0); context.complete(); } catch (SQLException e) { log.error("Failed to record startup in Webapp table.", e); } }
/** * 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 synchronized void startNewScheduler() throws SQLException, AuthorizeException { Context c = new Context(); harvestedCollectionService.exists(c); c.complete(); if (mainHarvestThread != null && harvester != null) { stopScheduler(); } harvester = new HarvestScheduler(); HarvestScheduler.setInterrupt(HarvestScheduler.HARVESTER_INTERRUPT_NONE); mainHarvestThread = new Thread(harvester); mainHarvestThread.start(); }
@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) { 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 resetScheduler() throws SQLException, AuthorizeException, IOException { Context context = new Context(); List<HarvestedCollection> harvestedCollections = harvestedCollectionService.findAll(context); for (HarvestedCollection hc : harvestedCollections) { hc.setHarvestStartTime(null); hc.setHarvestStatus(HarvestedCollection.STATUS_READY); harvestedCollectionService.update(context, hc); } }
/** * constructor, which just creates and object with a ready context * * @throws Exception if error */ protected CreateAdministrator() throws Exception { context = new Context(); groupService = EPersonServiceFactory.getInstance().getGroupService(); ePersonService = EPersonServiceFactory.getInstance().getEPersonService(); }
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(); }
/** * Test the operation of this class. * * @param argv <br>[0]: handle of an object for which to prepare XML metadata. * @throws Exception if error */ public static void main(String[] argv) throws Exception { String handle = argv[0]; DataCiteXMLCreator instance = new DataCiteXMLCreator(); Context context = new Context(); DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService() .resolveToObject(context, handle); System.out.println(instance.getXMLString(context, dso)); } }
/** * 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 RDFizer() { this.stdout = false; this.verbose = false; this.dryrun = false; this.lang = "TURTLE"; this.processed = new CopyOnWriteArraySet<UUID>(); this.context = new Context(Context.Mode.READ_ONLY); this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); this.contentServiceFactory = ContentServiceFactory.getInstance(); this.communityService = contentServiceFactory.getCommunityService(); this.itemService = contentServiceFactory.getItemService(); this.handleService = HandleServiceFactory.getInstance().getHandleService(); this.storage = RDFFactory.getInstance().getRDFStorage(); }