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);
}
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++;
}
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());
}
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;
}
Aggregations