Package org.dspace.core

Examples of org.dspace.core.Context


            }

        }
        log.debug("...DONE building names list size " + names.size());
        log.debug("Create DSpace context and use browse indexing");
        Context context = null;
        try
        {
            context = new Context();
            context.setIgnoreAuthorization(true);
           
            List<MetadataField> fieldsWithAuthoritySupport = metadataFieldWithAuthorityRP(context);
           
            BrowseIndex bi = BrowseIndex
                    .getBrowseIndex(researcherPotentialMatchLookupBrowserIndex);
            // now start up a browse engine and get it to do the work for us
            BrowseEngine be = new BrowseEngine(context);
            int count = 1;
            for (NameResearcherPage tempName : names)
            {
                log.info("work on " + tempName.getName() + " with identifier "
                        + tempName.getPersistentIdentifier() + " (" + count
                        + " of " + names.size() + ")");
                // set up a BrowseScope and start loading the values into it
                BrowserScope scope = new BrowserScope(context);
                scope.setBrowseIndex(bi);
                // scope.setOrder(order);
                scope.setFilterValue(tempName.getName());
                // scope.setFilterValueLang(valueLang);
                // scope.setJumpToItem(focus);
                // scope.setJumpToValue(valueFocus);
                // scope.setJumpToValueLang(valueFocusLang);
                // scope.setStartsWith(startsWith);
                // scope.setOffset(offset);
                scope.setResultsPerPage(Integer.MAX_VALUE);
                // scope.setSortBy(sortBy);
                scope.setBrowseLevel(1);
                // scope.setEtAl(etAl);

                BrowseInfo binfo = be.browse(scope);
                log.info("Find " + binfo.getResultCount()
                        + "item(s) in browsing...");
                bindItemsToRP(relationPreferenceService, context,
                        fieldsWithAuthoritySupport, tempName,
                        binfo.getItemResults(context));
                count++;
            }

        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        }
        finally
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
        }

    }
View Full Code Here


        generatePotentialMatches(context, researcher);
    }

    public static void generatePotentialMatches(ResearcherPage researcher)
    {
        Context context = null;
        try
        {
            context = new Context();
            generatePotentialMatches(context, researcher);
            context.complete();
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
        }
        finally
        {
            if (context != null && context.isValid())
                context.abort();
            }

    }
View Full Code Here

     * @param args
     */
    public static void main(String[] args) throws ParseException, SQLException
    {

        Context dspaceContext = new Context();
        dspaceContext.setIgnoreAuthorization(true);
        DSpace dspace = new DSpace();
        ApplicationService applicationService = dspace.getServiceManager()
                .getServiceByName("applicationService",
                        ApplicationService.class);

View Full Code Here

        this.dynamicField.pulisciAnagrafica();
    }

    public EPerson getDspaceUser()
    {
        Context context = null;
        EPerson eperson = null;

        try
        {
            context = new Context();
            if (epersonID != null)
            {
                eperson = EPerson.find(context, epersonID);
            }
        }
        catch (SQLException e)
        {
            log.error(e.getMessage());
        }
        finally
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
        }

        return eperson;
    }
View Full Code Here

     * details.
     */
    public static void main(String[] args)
    {
        log.info("#### START DELETE: -----" + new Date() + " ----- ####");
        Context dspaceContext = null;
        ApplicationContext context = null;
        try
        {
            dspaceContext = new Context();
            dspaceContext.turnOffAuthorisationSystem();

            DSpace dspace = new DSpace();
            ApplicationService applicationService = dspace.getServiceManager().getServiceByName(
                    "applicationService", ApplicationService.class);

            CommandLineParser parser = new PosixParser();

            Options options = new Options();
            options.addOption("h", "help", false, "help");

            options.addOption("r", "researcher", true, "RP id to delete");

            options.addOption("s", "silent", false, "no interactive mode");

            CommandLine line = parser.parse(options, args);

            if (line.hasOption('h'))
            {
                HelpFormatter myhelp = new HelpFormatter();
                myhelp.printHelp("ScriptHKURPDelete \n", options);
                System.out.println("\n\nUSAGE:\n ScriptHKURPDelete -r <id> \n");
                System.out
                        .println("Please note: add -s for no interactive mode");
                System.exit(0);
            }

            Integer rpId = null;
            boolean delete = false;
            boolean silent = line.hasOption('s');
            Item[] items = null;
            if (line.hasOption('r'))
            {
                rpId = ResearcherPageUtils.getRealPersistentIdentifier(line.getOptionValue("r"),ResearcherPage.class);
                ResearcherPage rp = applicationService.get(
                        ResearcherPage.class, rpId);

                if (rp == null)
                {
                    if (!silent)
                    {
                        System.out.println("RP not exist...exit");
                    }
                    log.info("RP not exist...exit");
                    System.exit(0);
                }

                log.info("Use browse indexing");

                BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex);
                // now start up a browse engine and get it to do the work for us
                BrowseEngine be = new BrowseEngine(dspaceContext);

                String authKey = ResearcherPageUtils.getPersistentIdentifier(rp);

                // set up a BrowseScope and start loading the values into it
                BrowserScope scope = new BrowserScope(dspaceContext);
                scope.setBrowseIndex(bi);
                // scope.setOrder(order);
                scope.setFilterValue(authKey);
                scope.setAuthorityValue(authKey);
                scope.setResultsPerPage(Integer.MAX_VALUE);
                scope.setBrowseLevel(1);

                BrowseInfo binfo = be.browse(scope);
                log.debug("Find " + binfo.getResultCount()
                        + "item(s) for the reseracher " + authKey);
                items = binfo.getItemResults(dspaceContext);
               
                if (!silent && rp != null)
                {
                    System.out.println(MESSAGE_ONE);
                   
                    // interactive mode
                    System.out.println("Attempting to remove Researcher Page:");
                    System.out.println("StaffNo:" + rp.getSourceID());
                    System.out.println("FullName:" + rp.getFullName());
                    System.out.println("the researcher has " + items.length + " relation(s) with item(s) in the HUB");
                    System.out.println();

                    System.out.println(QUESTION_ONE);
                    InputStreamReader isr = new InputStreamReader(System.in);
                    BufferedReader reader = new BufferedReader(isr);
                    String answer = reader.readLine();
                    if (answer.equals("yes"))
                    {
                        delete = true;
                    }
                    else
                    {
                        System.out.println("Exit without delete");
                        log.info("Exit without delete");
                        System.exit(0);
                    }

                }
                else
                {
                    delete = true;
                }
            }
            else
            {
                System.out
                        .println("\n\nUSAGE:\n ScriptHKURPDelete <-v> -r <RPid> \n");
                System.out.println("-r option is mandatory");
                log.error("-r option is mandatory");
                System.exit(1);
            }

            if (delete)
            {
                if (!silent)
                {
                    System.out.println("Deleting...");
                }
                log.info("Deleting...");
                cleanAuthority(dspaceContext, items, rpId);
                applicationService.delete(ResearcherPage.class, rpId);
                dspaceContext.complete();
            }

            if (!silent)
            {
                System.out.println("Ok...Bye");
            }
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e);
            throw new RuntimeException(e.getMessage(), e);
        }
        finally
        {
            if (dspaceContext != null && dspaceContext.isValid())
            {
                dspaceContext.abort();
            }
            if (context != null)
            {
                context.publishEvent(new ContextClosedEvent(context));
            }
View Full Code Here

    public static void reIndexItems(List<ResearcherPage> rps,
            ApplicationService applicationService) throws SQLException,
            BrowseException, IOException
    {
        log.info("Create DSpace context and use browse indexing");
        Context context = null;
        try
        {
            context = new Context();
            context.setIgnoreAuthorization(true);
            BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex);
            // now start up a browse engine and get it to do the work for us
            BrowseEngine be = new BrowseEngine(context);
           
            // we need to assure that the right names will be present in the browse
            IndexBrowse ib = new IndexBrowse(context);
            int count = 1;
            for (ResearcherPage rp : rps)
            {
                String authKey = ResearcherPageUtils
                        .getPersistentIdentifier(rp);
                log.debug("work on " + rp.getFullName() + "[staffno "
                        + rp.getSourceID() + "] with identifier " + authKey
                        + " (" + count + " of " + rps.size() + ")");
                // set up a BrowseScope and start loading the values into it
                BrowserScope scope = new BrowserScope(context);
                scope.setBrowseIndex(bi);
                // scope.setOrder(order);
                scope.setFilterValue(authKey);
                scope.setAuthorityValue(authKey);
                scope.setResultsPerPage(Integer.MAX_VALUE);
                scope.setBrowseLevel(1);

                BrowseInfo binfo = be.browse(scope);
                log.debug("Find " + binfo.getResultCount()
                        + "item(s) for the reseracher " + authKey);
                Item[] items = binfo.getItemResults(context);
                for (Item item : items)
                {
                    DSIndexer.indexContent(context, item, true);
                    ib.indexItem(item);
                }
            }
            context.commit();
            context.clearCache();
        }
        catch (DCInputsReaderException e)
        {
            log.error(e.getMessage());
        }
        finally
        {
            if (context != null && context.isValid())
                context.abort();
        }
    }
View Full Code Here

                + " access in the statistics core");
        HttpSolrServer solr = indexer.getSolr();
        indexer.deleteByType(Constants.ITEM);
        solr.commit();
        System.out.println("Remove old data");
        Context context = new Context();
        context.turnOffAuthorisationSystem();
        int i = 0;
        for (SolrDocument sd : sdl)
        {
            i++;
            System.out.println("Processed access #" + i + " of "
                    + sdl.getNumFound());
            SolrInputDocument sdi = ClientUtils.toSolrInputDocument(sd);
            Integer id = (Integer) sd.getFieldValue("id");
            Integer type = (Integer) sd.getFieldValue("type");

            DSpaceObject dso = DSpaceObject.find(context, type, id);
           
            // Do any additional indexing, depends on the plugins
            List<SolrStatsIndexPlugin> solrServiceIndexPlugins = new DSpace()
                    .getServiceManager().getServicesByType(
                            SolrStatsIndexPlugin.class);
            for (SolrStatsIndexPlugin solrServiceIndexPlugin : solrServiceIndexPlugins)
            {
                solrServiceIndexPlugin.additionalIndex(null, dso,
                        sdi);
            }

           
            context.removeCached(dso, id);
            solr.add(sdi);
        }
        solr.commit();
        solr.optimize();
View Full Code Here

            return;
        }

        ResearcherPage cris = (ResearcherPage) object;

        Context context = null;
        try
        {
            context = new Context();
            context.turnOffAuthorisationSystem();
            if(cris.getEpersonID()!=null) {
                delete(cris.getEpersonID(), cris.getId(), context);
            }
            context.complete();
        }
        catch (Exception e)
        {
            log.error("Failed to delete resource policy attached to RP just deleted"
                    + cris.getPublicPath() + " uuid:" + cris.getUuid());
            emailException(e);
        }
        finally
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
        }

    }
View Full Code Here

            return;
        }

        ResearcherPage cris = (ResearcherPage) object;

        Context context = null;
        try
        {
            context = new Context();
            context.turnOffAuthorisationSystem();
            if (cris.getEpersonID() != null)
            {
                ResourcePolicy resourcePolicy = ResourcePolicy.create(context);
                resourcePolicy.setAction(Constants.ADMIN);
                resourcePolicy.setEPerson(cris.getDspaceUser());
                resourcePolicy.setResource(cris);
                resourcePolicy.setResourceType(CrisConstants.RP_TYPE_ID);
                resourcePolicy.setResourceID(cris.getID());
                resourcePolicy.update();
            }
            context.complete();
        }
        catch (Exception e)
        {
            log.error("Failed to delete resource policy attached to RP just deleted"
                    + cris.getPublicPath() + " uuid:" + cris.getUuid());
            emailException(e);
        }
        finally
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
        }

    }
View Full Code Here

            return;
        }

        ResearcherPage cris = (ResearcherPage) object;

        Context context = null;
        try
        {
            context = new Context();
            context.turnOffAuthorisationSystem();
            if ((cris.getOldEpersonID() != null && !cris.getOldEpersonID()
                    .equals(cris.getEpersonID()))
                    || (cris.getOldEpersonID() == null && cris.getEpersonID() != null))
            {
                if (cris.getEpersonID() != null)
                {
                    ResourcePolicy resourcePolicy = ResourcePolicy
                            .create(context);
                    resourcePolicy.setAction(Constants.ADMIN);
                    resourcePolicy.setEPerson(cris.getDspaceUser());
                    resourcePolicy.setResource(cris);
                    resourcePolicy.setResourceType(CrisConstants.RP_TYPE_ID);
                    resourcePolicy.setResourceID(cris.getID());
                    resourcePolicy.update();
                }
                if (cris.getOldEpersonID() != null)
                {
                    delete(cris.getOldEpersonID(), cris.getId(), context);
                }
               
            }
            context.complete();
        }
        catch (Exception e)
        {
            log.error("Failed to delete resource policy attached to RP just deleted"
                    + cris.getPublicPath() + " uuid:" + cris.getUuid());
            emailException(e);
        }
        finally
        {
            if (context != null && context.isValid())
            {
                context.abort();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.dspace.core.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.