use of dk.dbc.opensearch.commons.repository.IRepositoryDAO in project solr-document-store by DBCDK.
the class SolrIndexer method unitFor.
@Lock(LockType.READ)
public String unitFor(String pid) throws RepositoryException {
try (IRepositoryDAO dao = daoProvider.getRepository()) {
IRepositoryIdentifier id = dao.createIdentifier(pid);
if (!dao.hasObject(id)) {
throw new IllegalStateException("Doesn't have pid: " + pid);
}
if (dao.getObjectState(id) == IRepositoryDAO.State.DELETED) {
return null;
}
ISysRelationsStream relations = dao.getSysRelationsStream(id);
IRepositoryIdentifier unit = relations.getUnitFor();
return unit.toString();
}
}
use of dk.dbc.opensearch.commons.repository.IRepositoryDAO in project solr-document-store by DBCDK.
the class SolrIndexer method buildDocuments.
@Lock(LockType.READ)
@SuppressFBWarnings(value = "ICAST_IDIV_CAST_TO_DOUBLE", justification = "trimming of number of digits for LogStash.Marker#append()")
public void buildDocuments(String pid, SolrIndexerJS jsWrapper, BiConsumer<String, SolrUpdaterCallback> function) throws Exception {
try (IRepositoryDAO dao = daoProvider.getRepository()) {
if (jsWrapper.isIndexableIdentifier(pid)) {
long starttime = System.nanoTime();
String trackingId = getTrackingId(dao, pid);
DBCTrackedLogContext.setTrackingId(trackingId);
String data = getObjectData(dao, pid);
SolrUpdaterCallback callback = new SolrUpdaterCallback(jsWrapper.getEnvironment(), trackingId, pid);
jsWrapper.createIndexData(dao, pid, data, callback, libraryRuleHandler);
documentsDeleted.inc(callback.getDeletedDocumentsCount());
documentsUpdated.inc(callback.getUpdatedDocumentsCount());
if (callback.getDeletedDocumentsCount() > 0 || callback.getUpdatedDocumentsCount() > 0) {
function.accept(data, callback);
} else {
log.info("Indexing {} skipped by javascript", pid);
}
long endtime = System.nanoTime();
log.info(LogAppender.getMarker(App.APP_NAME, pid, LogAppender.SUCCEDED).and(append("duration", ((endtime - starttime) / 10000L) / 100.0)).and(append("updates", callback.getUpdatedDocumentsCount())).and(append("deletes", callback.getDeletedDocumentsCount())), "Documents successfully build");
} else {
log.debug("object {} filtered", pid);
}
} catch (Exception ex) {
String error = String.format("Error calling indexing logic for '%s'", pid);
log.error(LogAppender.getMarker(App.APP_NAME, pid, LogAppender.FAILED), error);
throw ex;
} finally {
DBCTrackedLogContext.remove();
}
}
use of dk.dbc.opensearch.commons.repository.IRepositoryDAO in project solr-document-store by DBCDK.
the class SolrIndexer method workFor.
@Lock(LockType.READ)
public String workFor(String unit) throws RepositoryException {
if (unit == null) {
return null;
}
try (IRepositoryDAO dao = daoProvider.getRepository()) {
ISysRelationsStream relations = dao.getSysRelationsStream(dao.createIdentifier(unit));
IRepositoryIdentifier work = relations.getWorkFor();
return work.toString();
}
}
Aggregations