Search in sources :

Example 1 with IndexingStatus

use of org.orcid.persistence.jpa.entities.IndexingStatus in project ORCID-Source by ORCID.

the class OrcidIndexManagerImpl method persistProfileInformationForIndexingIfNecessary.

@Override
@Deprecated
public // now going via orcid-message-listener
void persistProfileInformationForIndexingIfNecessary(OrcidProfile orcidProfile) {
    String orcid = orcidProfile.getOrcidIdentifier().getPath();
    Date lastModifiedFromSolr = solrDao.retrieveLastModified(orcid);
    Date lastModifiedFromDb = orcidProfile.getOrcidHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime();
    if (lastModifiedFromDb.equals(lastModifiedFromSolr)) {
        // Check if re-indexing
        IndexingStatus indexingStatus = profileDao.retrieveIndexingStatus(orcid);
        if (!IndexingStatus.REINDEX.equals(indexingStatus)) {
            // If not re-indexing then skip
            LOG.info("Index is already up to date for orcid: {}", orcid);
            return;
        }
    }
    persistProfileInformationForIndexing(orcidProfile);
}
Also used : IndexingStatus(org.orcid.persistence.jpa.entities.IndexingStatus) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated)

Example 2 with IndexingStatus

use of org.orcid.persistence.jpa.entities.IndexingStatus in project ORCID-Source by ORCID.

the class ResaveProfiles method processOrcid.

private void processOrcid(final String orcid) {
    LOG.info("Resaving profile: {}", orcid);
    try {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfile(orcid);
                Date originalLastModified = orcidProfile.getOrcidHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime();
                IndexingStatus originalIndexingStatus = profileDao.find(orcid).getIndexingStatus();
                // Save it straight back - it will be saved back in the
                // new DB table automatically
                orcidProfileManager.updateOrcidProfile(orcidProfile);
                if (!updateLastModified) {
                    profileDao.updateLastModifiedDateAndIndexingStatusWithoutResult(orcid, originalLastModified, originalIndexingStatus);
                }
            }
        });
    } catch (RuntimeException e) {
        errorCount++;
        if (continueOnError) {
            LOG.error("Error saving profile: orcid={}", orcid, e);
            return;
        } else {
            throw e;
        }
    }
    doneCount++;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) TransactionStatus(org.springframework.transaction.TransactionStatus) IndexingStatus(org.orcid.persistence.jpa.entities.IndexingStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date)

Example 3 with IndexingStatus

use of org.orcid.persistence.jpa.entities.IndexingStatus in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method processProfilesWithFlagAndAddToMessageQueue.

/**
 * Simple method to be called by scheduler. Looks for profiles with REINDEX
 * flag and adds LastModifiedMessages to the REINDEX queue Then sets
 * indexing flag to DONE (although there is no guarantee it will be done!)
 */
private void processProfilesWithFlagAndAddToMessageQueue(IndexingStatus status, JmsDestination destination) {
    LOG.info("processing profiles with " + status.name() + " flag. sending to " + destination.name());
    List<Pair<String, IndexingStatus>> orcidsForIndexing = new ArrayList<>();
    List<IndexingStatus> indexingStatuses = new ArrayList<IndexingStatus>(1);
    indexingStatuses.add(status);
    boolean connectionIssue = false;
    do {
        orcidsForIndexing = profileDaoReadOnly.findOrcidsByIndexingStatus(indexingStatuses, INDEXING_BATCH_SIZE, new ArrayList<String>());
        LOG.info("processing batch of " + orcidsForIndexing.size());
        for (Pair<String, IndexingStatus> p : orcidsForIndexing) {
            String orcid = p.getLeft();
            Date last = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
            LastModifiedMessage mess = new LastModifiedMessage(orcid, last);
            if (messaging.send(mess, destination))
                profileDao.updateIndexingStatus(orcid, IndexingStatus.DONE);
            else
                connectionIssue = true;
        }
    } while (!connectionIssue && !orcidsForIndexing.isEmpty());
    if (connectionIssue)
        LOG.warn("ABORTED processing profiles with " + status.name() + " flag. sending to " + destination.name());
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) ArrayList(java.util.ArrayList) IndexingStatus(org.orcid.persistence.jpa.entities.IndexingStatus) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with IndexingStatus

use of org.orcid.persistence.jpa.entities.IndexingStatus in project ORCID-Source by ORCID.

the class ProfileDaoImpl method findOrcidsByIndexingStatus.

/**
 * Get a list of the ORCID id's with the given indexing status
 *
 * @param indexingStatuses
 *            The list of desired indexing status
 * @param maxResults
 *            Max number of results
 * @param orcidsToExclude
 *            List of ORCID id's to exclude from the results
 * @return a list of object arrays where the object[0] contains the orcid id
 *         and object[1] contains the indexing status
 */
@SuppressWarnings("unchecked")
@Override
public List<Pair<String, IndexingStatus>> findOrcidsByIndexingStatus(Collection<IndexingStatus> indexingStatuses, int maxResults, Collection<String> orcidsToExclude) {
    StringBuilder builder = new StringBuilder("SELECT p.orcid, p.indexing_status FROM profile p WHERE p.indexing_status IN :indexingStatus");
    if (!orcidsToExclude.isEmpty()) {
        builder.append(" AND p.orcid NOT IN :orcidsToExclude");
    }
    // Ordering by indexing status will force re-indexing to be lower
    // priority than normal indexing
    builder.append(" ORDER BY (p.last_modified > (NOW() - CAST('1' as INTERVAL HOUR))) DESC, indexing_status, p.last_modified");
    Query query = entityManager.createNativeQuery(builder.toString());
    query.setParameter("indexingStatus", IndexingStatus.getNames(indexingStatuses));
    if (!orcidsToExclude.isEmpty()) {
        query.setParameter("orcidsToExclude", orcidsToExclude);
    }
    query.setMaxResults(maxResults);
    List<Object[]> dbInfo = query.getResultList();
    List<Pair<String, IndexingStatus>> results = new ArrayList<Pair<String, IndexingStatus>>();
    dbInfo.stream().forEach(element -> {
        IndexingStatus i = element[1] == null ? null : IndexingStatus.valueOf((String) element[1]);
        Pair<String, IndexingStatus> pair = Pair.of((String) element[0], i);
        results.add(pair);
    });
    return results;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) IndexingStatus(org.orcid.persistence.jpa.entities.IndexingStatus) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

IndexingStatus (org.orcid.persistence.jpa.entities.IndexingStatus)4 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 LastModifiedDate (org.orcid.jaxb.model.message.LastModifiedDate)1 OrcidDeprecated (org.orcid.jaxb.model.message.OrcidDeprecated)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)1 LastModifiedMessage (org.orcid.utils.listener.LastModifiedMessage)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1