Search in sources :

Example 1 with IRepositoryDAO

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();
    }
}
Also used : ISysRelationsStream(dk.dbc.opensearch.commons.repository.ISysRelationsStream) IRepositoryIdentifier(dk.dbc.opensearch.commons.repository.IRepositoryIdentifier) IRepositoryDAO(dk.dbc.opensearch.commons.repository.IRepositoryDAO) Lock(javax.ejb.Lock)

Example 2 with IRepositoryDAO

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();
    }
}
Also used : IRepositoryDAO(dk.dbc.opensearch.commons.repository.IRepositoryDAO) RepositoryException(dk.dbc.opensearch.commons.repository.RepositoryException) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) EJBException(javax.ejb.EJBException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Lock(javax.ejb.Lock)

Example 3 with IRepositoryDAO

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();
    }
}
Also used : ISysRelationsStream(dk.dbc.opensearch.commons.repository.ISysRelationsStream) IRepositoryIdentifier(dk.dbc.opensearch.commons.repository.IRepositoryIdentifier) IRepositoryDAO(dk.dbc.opensearch.commons.repository.IRepositoryDAO) Lock(javax.ejb.Lock)

Aggregations

IRepositoryDAO (dk.dbc.opensearch.commons.repository.IRepositoryDAO)3 Lock (javax.ejb.Lock)3 IRepositoryIdentifier (dk.dbc.opensearch.commons.repository.IRepositoryIdentifier)2 ISysRelationsStream (dk.dbc.opensearch.commons.repository.ISysRelationsStream)2 RepositoryException (dk.dbc.opensearch.commons.repository.RepositoryException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 SQLException (java.sql.SQLException)1 EJBException (javax.ejb.EJBException)1 NamingException (javax.naming.NamingException)1