Package org.dspace.app.cris.service

Examples of org.dspace.app.cris.service.ApplicationService


            if (iter != null)
                iter.close();
        }

        DSpace dspace = new DSpace();
        ApplicationService applicationService = dspace.getServiceManager()
                .getServiceByName("applicationService",
                        ApplicationService.class);
        RelationPreferenceService relationPreferenceService = dspace
                .getServiceManager()
                .getServiceByName(
                        "org.dspace.app.cris.service.RelationPreferenceService",
                        RelationPreferenceService.class);

        List<RelationPreference> rejected = new ArrayList<RelationPreference>();
        for (RelationPreferenceConfiguration configuration : relationPreferenceService
                .getConfigurationService().getList())
        {
            if (configuration.getRelationConfiguration().getRelationClass().equals(Item.class))
            {
                rejected = applicationService
                        .findRelationsPreferencesByUUIDByRelTypeAndStatus(
                                researcher.getUuid(), configuration.getRelationConfiguration().getRelationName(),
                                RelationPreference.UNLINKED);
            }
        }
View Full Code Here


    {
        log.info("#### START AddPMCDataToRP: -----" + new Date()
                + " ----- ####");

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

        CrisSearchService searchService = dspace.getServiceManager()
                .getServiceByName(CrisSearchService.class.getName(),
                    CrisSearchService.class);
        PMCPersistenceService pmcService = dspace.getServiceManager()
                .getServiceByName(PMCPersistenceService.class.getName(),
                        PMCPersistenceService.class);

        List<ResearcherPage> rs = applicationService
                .getList(ResearcherPage.class);

        for (ResearcherPage rp : rs)
        {
            boolean updated = false;
            int itemsCited = 0;
            int citations = 0;
            SolrQuery query = new SolrQuery();
            query.setQuery("dc.identifier.pmid:[* TO *]");
            query.addFilterQuery("{!field f=author_authority}"
                    + ResearcherPageUtils.getPersistentIdentifier(rp),"NOT(withdrawn:true)");
            query.setFields("dc.identifier.pmid");
            query.setRows(Integer.MAX_VALUE);

            QueryResponse response = searchService.search(query);
            SolrDocumentList results = response.getResults();
            for (SolrDocument doc : results)
            {
                Integer pmid = null;
                try
                {
                    pmid = Integer.valueOf((String) doc
                            .getFirstValue("dc.identifier.pmid"));
                }
                catch (NumberFormatException e)
                {
                    log.warn("Found invalid pmid: "
                            + doc.getFieldValue("dc.identifier.pmid")
                            + " for rp: "
                            + ResearcherPageUtils.getPersistentIdentifier(rp));
                }
                if (pmid != null)
                {
                    PMCCitation pmccitation = pmcService.get(PMCCitation.class,
                            pmid);
                    if (pmccitation != null && pmccitation.getNumCitations() > 0)
                    {
                        itemsCited++;
                        citations += pmccitation.getNumCitations();
                    }
                }
            }

            updated = setValue(applicationService, rp, itemsCitedTP,
                    String.valueOf(itemsCited));
            // caution don't use the short-circuit OR operator (i.e || otherwise
            // only the first found pmcdata value will be recorded!)
            updated = updated
                    | setValue(applicationService, rp, citationsTP,
                            String.valueOf(citations));
            updated = updated
                    | setValue(applicationService, rp, itemsInPubmedTP,
                            String.valueOf(results.getNumFound()));

            if (StringUtils.isNotEmpty(itemsInPMCTP))
            {
                query = new SolrQuery();
                query.setQuery("dc.identifier.pmcid:[* TO *]");
                query.addFilterQuery("{!field f=author_authority}"
                        + ResearcherPageUtils.getPersistentIdentifier(rp),"NOT(withdrawn:true)");
                query.setRows(0);

                response = searchService.search(query);
                results = response.getResults();
                // caution don't use the short-circuit OR operator (i.e || otherwise
                // only the first found pmcdata value will be recorded!)
                updated = updated
                        | setValue(applicationService, rp, itemsInPMCTP,
                                String.valueOf(results.getNumFound()));
            }

            if (updated)
            {
                applicationService.saveOrUpdate(ResearcherPage.class, rp);
            }
        }
        log.info("#### END AddPMCDataToRP: -----" + new Date() + " ----- ####");
    }
View Full Code Here

    {

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

       for (ResearcherPage rp : applicationService
                .getList(ResearcherPage.class))
        {
            applicationService.saveOrUpdate(ResearcherPage.class, rp);
        }

        for (Project grant : applicationService
                .getList(Project.class))
        {
            applicationService.saveOrUpdate(Project.class, grant);
        }
       
    }
View Full Code Here

        indexer.deleteByType(CrisConstants.RP_TYPE_ID);
        rpsolr.commit();

        System.out.println("Remove old data");
       
        ApplicationService as = dspace.getServiceManager().getServiceByName(
                "applicationService", ApplicationService.class);
        i = 0;
        for (SolrDocument sd : sdl)
        {
            i++;
            System.out.println("Processed RP access #" + i + " of "
                    + sdl.getNumFound());
            SolrInputDocument sdi = ClientUtils.toSolrInputDocument(sd);
            Integer id = (Integer) sd.getFieldValue("id");

            ResearcherPage rp = as.get(ResearcherPage.class, id);
            if (rp == null)
                continue;

            // Do any additional indexing, depends on the plugins
            List<SolrStatsIndexPlugin> solrServiceIndexPlugins = new DSpace()
View Full Code Here

        DSpace dspace = new DSpace();
        VisualizationGraphSolrService service = dspace.getServiceManager()
                .getServiceByName("visualNetworkSolrService",
                        VisualizationGraphSolrService.class);

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

        CommandLineParser parser = new PosixParser();

        Options options = new Options();
        options.addOption("h", "help", false, "help");
        options.addOption("a", "all_connections", false,
                "Work on all connections read from configuration");
        options.addOption("s", "single_connection", true,
                "Work on single connection");

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

        if (line.hasOption('h'))
        {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("ScriptMetricsNetwork \n", options);
            System.out
                    .println("\n\nUSAGE:\n ScriptMetricsNetwork -a|-s <connection_name>] \n");

            System.exit(0);
        }

        if (line.hasOption('a') && line.hasOption('s'))
        {
            System.out
                    .println("\n\nUSAGE:\n ScriptMetricsNetwork -a|-s <connection_name>] \n");
            System.out.println("Insert either a or s like parameters");
            log.error("Either a or s like parameters");
            System.exit(1);
        }
        List<String> discardedConnection = new LinkedList<String>();
        List<String[]> discardedNode = new LinkedList<String[]>();
        List<String> connections = new LinkedList<String>();
        Integer importedNodes = 0;
        Boolean otherError = false;
        if (line.hasOption('a'))
        {

            String connectionsString = ConfigurationManager.getProperty(NetworkPlugin.CFG_MODULE, ConstantNetwork.CONFIG_CONNECTIONS);
            if (connectionsString == null || connectionsString.isEmpty())
            {
                System.out
                        .println("\n\nUSAGE:\n ScriptMetricsNetwork -a|-s <connection_name>] \n");
                System.out
                        .println("Error to get configuration values, check your dspace.cfg");
                log.error("Error to get configuration values, check your dspace.cfg");
                System.exit(1);
            }
            else
            {
                for (String connection : connectionsString.split(","))
                {
                    connections.add(connection);
                }
            }
        }
        else
        {
            if (line.hasOption('s'))
            {
                // get researcher by parameter
                String connection = line.getOptionValue("s");
                if (connection == null || connection.isEmpty())
                {
                    System.out
                            .println("\n\nUSAGE:\n ScriptMetricsNetwork -a|-s <connection_name>] \n");
                    System.out
                            .println("Connection name parameter is needed after option -s");
                    log.error("Connection name parameter is needed after option -s");
                    System.exit(1);
                }

                log.info("Script launched with -s parameter...it will work on connection with name "
                        + connection);
                connections.add(connection);
            }

        }

        external: for (String connection : connections)
        {
            boolean exit = false;
            // check rp configuration
            RPPropertiesDefinition rpPropertiesDefinition = null;
            rpPropertiesDefinition = applicationService
                    .findPropertiesDefinitionByShortName(
                            RPPropertiesDefinition.class,
                            ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1
                                    + connection);
            if (rpPropertiesDefinition == null)
            {
                System.out
                        .println("\n\nMETADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                                + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1
                                + connection
                                + " missed on configuration, add its on RP properties definition \n");
                log.error("METADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                        + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1
                        + connection
                        + " missed on configuration, add its on RP properties definition");
                exit = true;
            }
            rpPropertiesDefinition = null;
            rpPropertiesDefinition = applicationService
                    .findPropertiesDefinitionByShortName(
                            RPPropertiesDefinition.class,
                            ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2
                                    + connection);
            if (rpPropertiesDefinition == null)
            {
                System.out
                        .println("\n\nMETADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                                + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2
                                + connection
                                + " missed on configuration, add its on RP properties definition \n");
                log.error("METADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                        + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2
                        + connection
                        + " missed on configuration, add its on RP properties definition");
                exit = true;
            }
            rpPropertiesDefinition = null;
            rpPropertiesDefinition = applicationService
                    .findPropertiesDefinitionByShortName(
                            RPPropertiesDefinition.class,
                            ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3
                                    + connection);
            if (rpPropertiesDefinition == null)
            {
                System.out
                        .println("\n\nMETADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                                + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3
                                + connection
                                + " missed on configuration, add its on RP properties definition \n");
                log.error("METADATA NOT FOUND:\n ScriptMetricsNetwork has relieved that "
                        + ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3
                        + connection
                        + " missed on configuration, add its on RP properties definition");
                exit = true;
            }
            rpPropertiesDefinition = null;
            rpPropertiesDefinition = applicationService
                    .findPropertiesDefinitionByShortName(
                            RPPropertiesDefinition.class,
                            ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4
                                    + connection);
            if (rpPropertiesDefinition == null)
View Full Code Here

        {
            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)
            {
View Full Code Here

        log
                .info("#### START Script update researcher page's items search index: -----"
                        + new Date() + " ----- ####");

        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("a", "all_researcher", false,
                "Work on all researchers pages");
        options.addOption("s", "single_researcher", true,
                "Work on single researcher");
        options.addOption("d", "MODE_DATE", true,
                "Script work only on RP names modified since the date");
        options.addOption("D", "MODE_HOUR", true,
                "Script work only on RP names modified in the last n hours");

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

        if (line.hasOption('h'))
        {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("ScriptUpdateRPItemSearchIndex \n", options);
            System.out
                    .println("\n\nUSAGE:\n ScriptUpdateRPItemSearchIndex [-a (-d|-D <date>)|-s <researcher_identifier>] \n");

            System.exit(0);
        }

        if (line.hasOption('a') && line.hasOption('s'))
        {
            System.out
                    .println("\n\nUSAGE:\n ScriptBindItemToRP [-a (-d|-D <date>)|-s <researcher_identifier>] \n");
            System.out.println("Insert either a or s like parameters");
            log.error("Either a or s like parameters");
            System.exit(1);
        }

        List<ResearcherPage> rps = null;
        if (line.hasOption('a'))
        {
            log
                    .info("Script launched with -a parameter...it will work on all researcher...");
            // get list of name
            if (line.hasOption('d') || line.hasOption('D'))
            {

                try
                {

                    Date nameTimestampLastModified;
                    String date_string = line.getOptionValue("d");
                    if (line.hasOption('D'))
                    {
                        date_string = line.getOptionValue("D");
                        long hour = Long.parseLong(date_string);
                        Date now = new Date();
                        nameTimestampLastModified = new Date(now.getTime()
                                - (hour * 60 * 60000));
                        log.info("...it will work on RP modified between "
                                + nameTimestampLastModified + " and " + now);
                    }
                    else
                    {
                        nameTimestampLastModified = dateFormat.parse(date_string);
                        log.info("...it will work on RP modified after ..."
                                + date_string);
                    }

                    rps = applicationService
                            .getResearchersPageByNamesTimestampLastModified(nameTimestampLastModified);
                }
                catch (java.text.ParseException e)
                {
                    log.error("Error parsing the date", e);
                    System.exit(1);
                }
            }
            else
            {
                log.info("...it will work on all researcher...");
                rps = applicationService.getList(ResearcherPage.class);
            }
            reIndexItems(rps, applicationService);
        }
        else
        {
            if (line.hasOption('s'))
            {
                // get researcher by parameter
                String rp = line.getOptionValue("s");
                if (rp == null || rp.isEmpty())
                {
                    System.out
                            .println("\n\nUSAGE:\n ScriptBindItemToRP [-a|-s <researcher_identifier>] \n");
                    System.out
                            .println("Researcher id parameter is needed after option -s");
                    log
                            .error("Researcher id parameter is needed after option -s");
                    System.exit(1);
                }

                log
                        .info("Script launched with -s parameter...it will work on researcher with rp identifier "
                                + rp);
                rps = new LinkedList<ResearcherPage>();
                ResearcherPage researcher = applicationService
                        .get(ResearcherPage.class, Integer.parseInt(rp
                                .substring(2)));
                rps.add(researcher);
                reIndexItems(rps, applicationService);
            }
View Full Code Here

        DSpace dspace = new DSpace();
               
        RelationPreferenceService relationPreferenceService = dspace.getServiceManager().getServiceByName(
                "org.dspace.app.cris.service.RelationPreferenceService", RelationPreferenceService.class);
        ApplicationService applicationService = dspace.getServiceManager().getServiceByName(
                "applicationService", ApplicationService.class);
       
        CommandLineParser parser = new PosixParser();

        Options options = new Options();
        options.addOption("h", "help", false, "help");
        options.addOption("a", "all_researcher", false,
                "Work on all researchers pages");
        options.addOption("s", "single_researcher", true,
                "Work on single researcher");
        options.addOption("d", "MODE_DATE", true,
                "Script work only on RP names modified after this date");
        options.addOption("D", "MODE_HOUR", true,
                "Script work only on RP names modified in this hours range");

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

        if (line.hasOption('h'))
        {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("ScriptBindItemToRP \n", options);
            System.out
                    .println("\n\nUSAGE:\n ScriptBindItemToRP [-a (-d|-D <date>)|-s <researcher_identifier>] \n");

            System.exit(0);
        }

        if (line.hasOption('a') && line.hasOption('s'))
        {
            System.out
                    .println("\n\nUSAGE:\n ScriptBindItemToRP [-a (-d|-D <date>)|-s <researcher_identifier>] \n");
            System.out.println("Insert either a or s like parameters");
            log.error("Either a or s like parameters");
            System.exit(1);
        }

        List<ResearcherPage> rps = null;
        if (line.hasOption('a'))
        {
            log
                    .info("Script launched with -a parameter...it will work on all researcher...");
            // get list of name
            if (line.hasOption('d') || line.hasOption('D'))
            {

                try
                {
                    Date nameTimestampLastModified;
                    String date_string = line.getOptionValue("d");
                    if (line.hasOption('D'))
                    {
                        date_string = line.getOptionValue("D");
                        long hour = Long.parseLong(date_string);
                        Date now = new Date();
                        nameTimestampLastModified = new Date(now.getTime()
                                - (hour * 60 * 60000));
                        log.info("...it will work on RP modified between "
                                + nameTimestampLastModified + " and " + now);
                    }
                    else
                    {
                        nameTimestampLastModified = dateFormat.parse(date_string);
                        log.info("...it will work on RP modified after ..."
                                + date_string);
                    }

                    rps = applicationService
                            .getResearchersPageByNamesTimestampLastModified(nameTimestampLastModified);
                }
                catch (java.text.ParseException e)
                {
                    log
                            .error("Error parsing the date", e);
                    System.exit(1);
                }
            }
            else
            {
                log.info("...it will work on all researcher...");
                rps = applicationService.getList(ResearcherPage.class);
            }
            BindItemToRP.work(rps, relationPreferenceService);
        }
        else
        {
            if (line.hasOption('s'))
            {
                // get researcher by parameter
                String rp = line.getOptionValue("s");
                if (rp == null || rp.isEmpty())
                {
                    System.out
                            .println("\n\nUSAGE:\n ScriptBindItemToRP [-a|-s <researcher_identifier>] \n");
                    System.out
                            .println("Researcher id parameter is needed after option -s");
                    log
                            .error("Researcher id parameter is needed after option -s");
                    System.exit(1);
                }

                log
                        .info("Script launched with -s parameter...it will work on researcher with rp identifier "
                                + rp);
                rps = new LinkedList<ResearcherPage>();
                ResearcherPage researcher = applicationService
                        .get(ResearcherPage.class, Integer.parseInt(rp
                                .substring(2)));
                rps.add(researcher);
                BindItemToRP.work(rps, relationPreferenceService);
            }
View Full Code Here

TOP

Related Classes of org.dspace.app.cris.service.ApplicationService

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.