Skip to content

Commit

Permalink
Issues #814 #815
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel.stastny committed Apr 13, 2021
1 parent 3417ad6 commit ae6f13c
Show file tree
Hide file tree
Showing 93 changed files with 2,529 additions and 584 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repositories {

allprojects {
group = 'cz.incad.kramerius'
version = '5.5.0'
version = '5.6.0'
}

/**
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/cz/incad/kramerius/SolrAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public interface SolrAccess {
*/
public ObjectModelsPath[] getPathOfModels(String pid) throws IOException;

public ObjectModelsPath[] getPathOfModels(Document doc) throws IOException;


/**
* Wrapper allows to return ObjectPidPaths and ObjectModelsPath in one response
* Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.6
6.6.7
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import cz.incad.kramerius.statistics.StatisticReport;
import cz.incad.kramerius.statistics.StatisticsAccessLog;
import cz.incad.kramerius.statistics.StatisticsAccessLogSupport;
import cz.incad.kramerius.statistics.accesslogs.AggregatedAccessLogs;
import cz.incad.kramerius.utils.conf.KConfiguration;

public class GenerateDeepZoomCacheModule extends AbstractModule {
Expand All @@ -34,7 +35,7 @@ protected void configure() {
// necessary to have checked access to fedora.
bind(FedoraAccess.class).annotatedWith(Names.named("securedFedoraAccess")).to(FedoraAccessImpl.class)
.in(Scopes.SINGLETON);
bind(StatisticsAccessLog.class).to(NoStatistics.class).in(Scopes.SINGLETON);
bind(AggregatedAccessLogs.class).to(NoStatistics.class).in(Scopes.SINGLETON);
bind(KConfiguration.class).toInstance(KConfiguration.getInstance());
bind(DeepZoomTileSupport.class).to(TileSupportImpl.class);

Expand All @@ -45,7 +46,7 @@ protected void configure() {
bind(DeepZoomFlagService.class).to(DeepZoomFlagServiceImpl.class).in(Scopes.SINGLETON);
}

public static class NoStatistics implements StatisticsAccessLog {
public static class NoStatistics extends AggregatedAccessLogs {

@Override
public StatisticReport[] getAllReports() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import cz.incad.kramerius.FedoraAccess;
import cz.incad.kramerius.statistics.StatisticsAccessLog;
import cz.incad.kramerius.statistics.accesslogs.AggregatedAccessLogs;
import cz.incad.kramerius.utils.FedoraUtils;
import cz.incad.kramerius.utils.conf.KConfiguration;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
Expand All @@ -25,35 +27,68 @@
*/
public class CachedFedoraAccessImpl extends FedoraAccessImpl implements FedoraAccess {

private static Cache<String, Document> cache;

private static final String CACHE_ALIAS = "FedoraRelsExtCache";
private static Cache<String, Document> xmlscache;

private static final String XMLS_CACHE_ALIAS = "FedoraXMLSCache";

@Inject
public CachedFedoraAccessImpl(KConfiguration configuration, @Nullable StatisticsAccessLog accessLog,
public CachedFedoraAccessImpl(KConfiguration configuration, @Nullable AggregatedAccessLogs accessLog,
CacheManager cacheManager) throws IOException {
super(configuration, accessLog);

cache = cacheManager.getCache(CACHE_ALIAS, String.class, Document.class);
if (cache == null) {
cache = cacheManager.createCache(CACHE_ALIAS,

xmlscache = cacheManager.getCache(XMLS_CACHE_ALIAS, String.class, Document.class);
if (xmlscache == null) {
xmlscache = cacheManager.createCache(XMLS_CACHE_ALIAS,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Document.class,
ResourcePoolsBuilder.heap(1000).offheap(32, MemoryUnit.MB))
ResourcePoolsBuilder.heap(3000).offheap(32, MemoryUnit.MB))
.withExpiry(Expirations.timeToLiveExpiration(
Duration.of(configuration.getCacheTimeToLiveExpiration(), TimeUnit.SECONDS))).build());
}


}


private String cacheKey(String pid, String stream) {
return pid +"/"+stream;
}

@Override
public Document getRelsExt(String pid) throws IOException {
Document relsExt = cache.get(pid);

Document relsExt = xmlscache.get(cacheKey(pid, FedoraUtils.RELS_EXT_STREAM));
if (relsExt != null) { //cache hit
return relsExt;
} else { //cache miss
relsExt = super.getRelsExt(pid);
cache.put(pid, relsExt);
xmlscache.put(cacheKey(pid, FedoraUtils.RELS_EXT_STREAM), relsExt);
return relsExt;
}
}

@Override
public Document getBiblioMods(String pid) throws IOException {
Document mods = xmlscache.get(cacheKey(pid, FedoraUtils.BIBLIO_MODS_STREAM));
if (mods != null) { //cache hit
return mods;
} else { //cache miss
mods = super.getBiblioMods(pid);
xmlscache.put(cacheKey(pid, FedoraUtils.BIBLIO_MODS_STREAM), mods);
return mods;
}
}

@Override
public Document getDC(String pid) throws IOException {
Document dc = xmlscache.get(cacheKey(pid, FedoraUtils.DC_STREAM));
if (dc != null) { //cache hit
return dc;
} else { //cache miss
dc = super.getDC(pid);
xmlscache.put(cacheKey(pid, FedoraUtils.DC_STREAM), dc);
return dc;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.inject.Inject;

import cz.incad.kramerius.*;
import cz.incad.kramerius.statistics.StatisticsAccessLog;
import cz.incad.kramerius.statistics.accesslogs.AggregatedAccessLogs;
import cz.incad.kramerius.utils.FedoraUtils;
import cz.incad.kramerius.utils.IOUtils;
import cz.incad.kramerius.utils.RESTHelper;
Expand Down Expand Up @@ -65,10 +65,10 @@ public class FedoraAccessImpl implements FedoraAccess {
private StringTemplateGroup xpaths;
private XPathFactory xPathFactory;

private StatisticsAccessLog accessLog;
private AggregatedAccessLogs accessLog;

@Inject
public FedoraAccessImpl(KConfiguration configuration, @Nullable StatisticsAccessLog accessLog) throws IOException {
public FedoraAccessImpl(KConfiguration configuration, @Nullable AggregatedAccessLogs accessLog) throws IOException {
super();
this.configuration = configuration;
this.xPathFactory = XPathFactory.newInstance();
Expand Down
64 changes: 31 additions & 33 deletions common/src/main/java/cz/incad/kramerius/impl/SolrAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,24 @@ public Document getSolrDataDocumentByHandle(String handle) throws IOException {
public ObjectModelsPath[] getPathOfModels(String pid) throws IOException {
if (SpecialObjects.isSpecialObject(pid))
return new ObjectModelsPath[] { ObjectModelsPath.REPOSITORY_PATH };
try {
Document doc = getSolrDataDocument(pid);
return getPathOfModels(doc);
} catch (XPathExpressionException e) {
throw new IOException(e);
}

Document doc = getSolrDataDocument(pid);
return getPathOfModels(doc);
}

private ObjectModelsPath[] getPathOfModels(Document doc) throws XPathExpressionException {
synchronized (doc) {
List<String> disected = SolrUtils.disectModelPaths(doc);
ObjectModelsPath[] paths = new ObjectModelsPath[disected.size()];
for (int i = 0; i < paths.length; i++) {
String[] models = disected.get(i).split("/");
paths[i] = new ObjectModelsPath(models);
public ObjectModelsPath[] getPathOfModels(Document doc) throws IOException {
try {
synchronized (doc) {
List<String> disected = SolrUtils.disectModelPaths(doc);
ObjectModelsPath[] paths = new ObjectModelsPath[disected.size()];
for (int i = 0; i < paths.length; i++) {
String[] models = disected.get(i).split("/");
paths[i] = new ObjectModelsPath(models);
}
return paths;
}
return paths;
} catch (XPathExpressionException e) {
throw new IOException(e);
}
}

Expand All @@ -177,25 +178,22 @@ public Map<String, AbstractObjectPath[]> getPaths(String pid) throws IOException
} catch (LexerException e1) {
throw new IOException(e1);
}
try {
if (SpecialObjects.isSpecialObject(pid)) {
Map<String, AbstractObjectPath[]> map = new HashMap<String, AbstractObjectPath[]>();
map.put(ObjectPidsPath.class.getName(), new ObjectPidsPath[] { ObjectPidsPath.REPOSITORY_PATH });
map.put(ObjectModelsPath.class.getName(), new ObjectModelsPath[] { ObjectModelsPath.REPOSITORY_PATH });
return map;
} else {
Map<String, AbstractObjectPath[]> map = new HashMap<String, AbstractObjectPath[]>();
Document doc = getSolrDataDocument(pid);
ObjectModelsPath[] pathsOfModels = getPathOfModels(doc);
map.put(ObjectModelsPath.class.getName(), pathsOfModels);

ObjectPidsPath[] paths = getPath(parser.isDatastreamPid() ? parser.getDataStream() : null, doc);
map.put(ObjectPidsPath.class.getName(), paths);

return map;
}
} catch (XPathExpressionException e) {
throw new IOException(e);

if (SpecialObjects.isSpecialObject(pid)) {
Map<String, AbstractObjectPath[]> map = new HashMap<String, AbstractObjectPath[]>();
map.put(ObjectPidsPath.class.getName(), new ObjectPidsPath[] { ObjectPidsPath.REPOSITORY_PATH });
map.put(ObjectModelsPath.class.getName(), new ObjectModelsPath[] { ObjectModelsPath.REPOSITORY_PATH });
return map;
} else {
Map<String, AbstractObjectPath[]> map = new HashMap<String, AbstractObjectPath[]>();
Document doc = getSolrDataDocument(pid);
ObjectModelsPath[] pathsOfModels = getPathOfModels(doc);
map.put(ObjectModelsPath.class.getName(), pathsOfModels);

ObjectPidsPath[] paths = getPath(parser.isDatastreamPid() ? parser.getDataStream() : null, doc);
map.put(ObjectPidsPath.class.getName(), paths);

return map;
}
}

Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/cz/incad/kramerius/processes/res/lp.st
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,21 @@
</templates>
</process>
<process>
<id>nkplogs</id>
<description>Generate access logs for NKP</description>
<!-- spoustena trida -->
<mainClass>cz.incad.kramerius.statistics.impl.nkp.NKPLogProcess</mainClass>
<!-- standardni vystup -->
<standardOs>lrOut</standardOs>
<!-- err vystup -->
<errOs>lrErr</errOs>
<javaProcessParameters>-Xmx1024m -Xms256m</javaProcessParameters>
<templates>
<input class="cz.incad.kramerius.statistics.impl.nkp.ParametrizedNKPInputTemplate"></input>
</templates>
</process>
</processes>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.logging.Logger;

import cz.incad.kramerius.statistics.accesslogs.AggregatedAccessLogs;
import org.w3c.dom.Document;

import com.google.common.collect.Ordering;
Expand Down Expand Up @@ -179,7 +180,7 @@ class SortingModule extends AbstractModule {
@Override
protected void configure() {
bind(FedoraAccess.class).annotatedWith(Names.named("rawFedoraAccess")).to(FedoraAccessImpl.class).in(Scopes.SINGLETON);
bind(StatisticsAccessLog.class).to(GenerateDeepZoomCacheModule.NoStatistics.class).in(Scopes.SINGLETON);
bind(AggregatedAccessLogs.class).to(GenerateDeepZoomCacheModule.NoStatistics.class).in(Scopes.SINGLETON);
bind(KConfiguration.class).toInstance(KConfiguration.getInstance());
bind(RelationService.class).to(RelationServiceImpl.class).in(Scopes.SINGLETON);
bind(SortingService.class).to(SortingServiceImpl.class).in(Scopes.SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Map;

import cz.incad.kramerius.statistics.filters.DateFilter;
import cz.incad.kramerius.statistics.filters.StatisticsFiltersContainer;
import cz.incad.kramerius.utils.database.Offset;

Expand All @@ -47,6 +46,8 @@ public interface StatisticReport {
public static final String DATE_FROM = "from";
public static final String DATE_TO = "to";



/**
* Returns reporting page
*
Expand Down Expand Up @@ -86,6 +87,15 @@ public interface StatisticReport {
*
* @param sup
*/
public void processAccessLog(ReportedAction action, StatisticsReportSupport sup,
StatisticsFiltersContainer container) throws StatisticsReportException;
public void processAccessLog(ReportedAction action, StatisticsReportSupport sup, StatisticsFiltersContainer container) throws StatisticsReportException;

/**
* Returns true if report is possible
* @param action Reporting action
* @param container Filters container
*/
public boolean verifyFilters(ReportedAction action, StatisticsFiltersContainer container);



}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ public interface StatisticsAccessLog {
* @return
*/
public StatisticReport getReportById(String reportId);





}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ public interface StatisticsAccessLogSupport {
* @param detail
*/
public void processDetailRecord(Map<String, Object> detail);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cz.incad.kramerius.statistics.accesslogs;

import cz.incad.kramerius.statistics.ReportedAction;
import cz.incad.kramerius.statistics.StatisticsAccessLog;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractStatisticsAccessLog implements StatisticsAccessLog {

static Map<String, ReportedAction> ACTIONS = new HashMap<>();
static {
AbstractStatisticsAccessLog.ACTIONS.put("img", ReportedAction.READ);
AbstractStatisticsAccessLog.ACTIONS.put("pdf", ReportedAction.PDF);
AbstractStatisticsAccessLog.ACTIONS.put("print", ReportedAction.PRINT);
AbstractStatisticsAccessLog.ACTIONS.put("zoomify", ReportedAction.READ);
}

protected ThreadLocal<ReportedAction> reportedAction = new ThreadLocal<ReportedAction>();


}
Loading

0 comments on commit ae6f13c

Please sign in to comment.