Search in sources :

Example 1 with LoadOptions

use of org.orcid.core.manager.LoadOptions in project ORCID-Source by ORCID.

the class ProfileEventManager method callOnceOnAll.

private void callOnceOnAll(final String classStr) throws InterruptedException {
    ProfileEvent dummyPe = (ProfileEvent) context.getBean(classStr, (ProfileEvent) null);
    long startTime = System.currentTimeMillis();
    @SuppressWarnings("unchecked") List<String> orcids = Collections.EMPTY_LIST;
    int doneCount = 0;
    do {
        orcids = getProfileDao().findByMissingEventTypes(CHUNK_SIZE, dummyPe.outcomes(), null, true);
        Set<ProfileEvent> callables = new HashSet<ProfileEvent>();
        for (final String orcid : orcids) {
            LOG.info("Calling bean " + classStr + " for " + orcid);
            // TODO: parameterize load options.
            OrcidProfile orcidProfile = getOrcidProfileManager().retrieveOrcidProfile(orcid, new LoadOptions(true, false, true));
            callables.add((ProfileEvent) context.getBean(classStr, orcidProfile));
            doneCount++;
        }
        List<Future<ProfileEventResult>> futures = pool.invokeAll(callables);
        for (Future<ProfileEventResult> future : futures) {
            ProfileEventResult per = null;
            try {
                per = future.get();
            } catch (ExecutionException e) {
                LOG.error("failed calling task ", e);
            }
            getProfileEventDao().persist(new ProfileEventEntity(per.getOrcidId(), per.getOutcome()));
        }
        LOG.info("Current done count: {}", doneCount);
    } while (!orcids.isEmpty());
    long endTime = System.currentTimeMillis();
    String timeTaken = DurationFormatUtils.formatDurationHMS(endTime - startTime);
    LOG.info("Profile Event " + classStr + ": doneCount={}, timeTaken={} (H:m:s.S)", doneCount, timeTaken);
}
Also used : ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) LoadOptions(org.orcid.core.manager.LoadOptions) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 LoadOptions (org.orcid.core.manager.LoadOptions)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 ProfileEventEntity (org.orcid.persistence.jpa.entities.ProfileEventEntity)1