Skip to content

Commit

Permalink
Issue #318
Browse files Browse the repository at this point in the history
  • Loading branch information
pavels authored and jirikrepl committed Apr 21, 2016
1 parent 0bcc704 commit b18fe50
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 51 deletions.
39 changes: 24 additions & 15 deletions common/src/main/java/cz/incad/kramerius/MostDesirable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@

/**
* Most desirable objects in application
*
* @author pavels
*
*/
public interface MostDesirable {

/**
* Save access to some object
* @param uuid UUID of object
* @param date access date
*/
public void saveAccess(String uuid, Date date);

/**
* Return most desirable objects
* @param count How many objects do you want ?
* @param offset Offset
* @param model Filtered model
* @return
*/
public List<String> getMostDesirable(int count, int offset, String model);
/**
* Save access to some object
*
* @param uuid
* UUID of object
* @param date
* access date
*/
public void saveAccess(String uuid, Date date);

/**
* Return most desirable objects
*
* @param count
* How many objects do you want ?
* @param offset
* Offset
* @param model
* Filtered model
* @return
*/
public List<String> getMostDesirable(int count, int offset, String model);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.SimpleFormatter;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;

import cz.incad.kramerius.FedoraAccess;
import cz.incad.kramerius.MostDesirable;
import cz.incad.kramerius.utils.conf.KConfiguration;
import cz.incad.kramerius.utils.database.JDBCQueryTemplate;
import cz.incad.kramerius.utils.database.JDBCUpdateTemplate;

public class MostDesirableImpl implements MostDesirable {


private Provider<Connection> provider;
private FedoraAccess fedoraAccess;


@Inject
public MostDesirableImpl(
@Named("kramerius4") Provider<Connection> provider,
Expand All @@ -36,6 +42,10 @@ public MostDesirableImpl(

@Override
public List<String> getMostDesirable(int count, int offset, String model) {
int ll = KConfiguration.getInstance().getConfiguration().getInt("most.mostdesirable.numberofdays",100);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, (-1)*ll);
Date time = cal.getTime();
if (model != null) {
return new JDBCQueryTemplate<String>(provider.get(), true) {
@Override
Expand All @@ -44,7 +54,7 @@ public boolean handleRow(ResultSet rs, List<String> returnsList)
returnsList.add(rs.getString("uuid"));
return super.handleRow(rs, returnsList);
}
}.executeQuery("SELECT count(uuid) as count , uuid, model FROM desirable where model = ? group by uuid, model order by count DESC LIMIT ? OFFSET ?", model, count, offset);
}.executeQuery("SELECT count(uuid) as count , uuid, model FROM desirable where model = ? and access > ? group by uuid, model order by count DESC LIMIT ? OFFSET ?", model, new java.sql.Timestamp(time.getTime()), count, offset);
} else {
return new JDBCQueryTemplate<String>(provider.get(), true) {
@Override
Expand All @@ -53,10 +63,13 @@ public boolean handleRow(ResultSet rs, List<String> returnsList)
returnsList.add(rs.getString("uuid"));
return super.handleRow(rs, returnsList);
}
}.executeQuery("SELECT count(uuid) as count , uuid FROM desirable group by uuid order by count DESC LIMIT ? OFFSET ?", count, offset);
}.executeQuery("SELECT count(uuid) as count , uuid FROM desirable where access > ? group by uuid order by count DESC LIMIT ? OFFSET ?", new java.sql.Timestamp(time.getTime()), count, offset);
}
}




@Override
public void saveAccess(String uuid, Date date) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import cz.incad.kramerius.AbstractObjectPath;
import cz.incad.kramerius.FedoraAccess;
import cz.incad.kramerius.MostDesirable;
import cz.incad.kramerius.ObjectModelsPath;
import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.ProcessSubtreeException;
Expand Down Expand Up @@ -99,6 +100,9 @@ public enum FirstPage {
SimplePDFService simplePdfService;


@Inject
MostDesirable mostDesirable;


@GET
@Path("conf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public Response part(@QueryParam("pid") String pid,
if (pid != null) {
File fileToDelete = null;
try {
this.mostDesirable.saveAccess(pid, new Date());

pid = this.fedoraAccess.findFirstViewablePid(pid);
BufferedImage bufImage = KrameriusImageSupport.readImage(pid,FedoraUtils.IMG_FULL_STREAM, this.fedoraAccess, 0);

Expand Down Expand Up @@ -254,6 +256,10 @@ public Response selection(@QueryParam("pids") String pidsParam,
String[] pids = pidsParam.split(",");
// max number test
ConfigurationUtils.checkNumber(pids);
for (String p : pids) {
this.mostDesirable.saveAccess(p, new Date());
}

Rectangle formatRect = formatRect(format);
final File generatedPDF = super.selection(pids, formatRect, fp);
final InputStream fis = new FileInputStream(generatedPDF);
Expand Down Expand Up @@ -328,6 +334,8 @@ public Response parent(@QueryParam("pid") String pid,
if (acquired) {
try {

this.mostDesirable.saveAccess(pid, new Date());

AbstractPDFResource.FirstPage fp = pageType != null ? AbstractPDFResource.FirstPage
.valueOf(pageType) : AbstractPDFResource.FirstPage.TEXT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

import cz.incad.Kramerius.AbstractImageServlet;
import cz.incad.Kramerius.imaging.utils.ZoomChangeFromReplicated;
import cz.incad.kramerius.MostDesirable;
import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.SolrAccess;
import cz.incad.kramerius.imaging.DeepZoomCacheService;
Expand Down Expand Up @@ -92,6 +93,9 @@ public class ZoomifyServlet extends AbstractImageServlet {

@Inject
SolrAccess solrAccess;

@Inject
MostDesirable mostDesirable;


@Override
Expand Down Expand Up @@ -160,6 +164,8 @@ private void renderXMLDescriptor(String pid, HttpServletRequest req, HttpServlet

setDateHaders(pid,FedoraUtils.IMG_FULL_STREAM, resp);
setResponseCode(pid,FedoraUtils.IMG_FULL_STREAM, req, resp);
mostDesirable.saveAccess(pid, new java.util.Date());

String relsExtUrl = RelsExtHelper.getRelsExtTilesUrl(pid, this.fedoraAccess);
if (!relsExtUrl.equals(RelsExtHelper.CACHE_RELS_EXT_LITERAL)) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cz.incad.Kramerius.views.inc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import com.google.inject.Inject;
import com.google.inject.Provider;

import cz.incad.kramerius.MostDesirable;
import cz.incad.kramerius.utils.conf.KConfiguration;

public class MostDesirableViewObject {

public static final Logger LOGGER = Logger.getLogger(MostDesirableViewObject.class.getName());

public static final int NUMBER_OF_DESIRABLE_ITEMS = 18;

@Inject
MostDesirable mostDesirable;



public List<String> getPids() {

List<String> pids = new ArrayList<String>();
List<String> list = KConfiguration.getInstance().getConfiguration().getList("most.desirable.models",
Arrays.asList(
"monograph",
"periodical",
"soundrecording",
"manuscript",
"map",
"sheetmusic",
"volume",
"periodicalitem",
"monographunit",
"internalpart",
"article",
"supplement",
"page")
);

for (String model : list) {
List<String> found = this.mostDesirable.getMostDesirable(NUMBER_OF_DESIRABLE_ITEMS, 0, model);
pids.addAll(found);
if (pids.size() >= NUMBER_OF_DESIRABLE_ITEMS) {
break;
}
}
return pids;
}
}
54 changes: 20 additions & 34 deletions search/web/inc/home/mostDesirables.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,26 @@
<%@page import="cz.incad.kramerius.utils.FedoraUtils"%>
<%@page import="cz.incad.kramerius.FedoraAccess"%>
<%@page import="cz.incad.kramerius.utils.conf.KConfiguration"%>
<%
<%@ taglib uri="/WEB-INF/tlds/cmn.tld" prefix="view"%>

Injector ctxInj = (Injector)application.getAttribute(Injector.class.getName());
KConfiguration kconfig = ctxInj.getProvider(KConfiguration.class).get();
pageContext.setAttribute("kconfig", kconfig);
pageContext.setAttribute("lrProcessManager",ctxInj.getInstance(LRProcessManager.class));
pageContext.setAttribute("dfManager",ctxInj.getInstance(DefinitionManager.class));
LocalizationContext lctx= ctxInj.getProvider(LocalizationContext.class).get();
pageContext.setAttribute("lctx", lctx);
<view:kconfig var="kConfigSolrHost" key="solrHost" />

FedoraAccess fedoraAccess = ctxInj.getInstance(com.google.inject.Key.get(FedoraAccess.class, com.google.inject.name.Names.named("securedFedoraAccess")));

List<String> uuids = (List<String>)ctxInj.getInstance(MostDesirable.class).getMostDesirable(18, 0, null);
Iterator it = uuids.iterator();
String itemUrl;
String path = "";
for(String pid :uuids){
//itemUrl = "./item.jsp?pid="+ pi + "&pid_path=" + uuid + "&path=" + path;
//imagePid = "thumb?uuid=" + FedoraUtils.findFirstPagePid("uuid:" + pid);
pageContext.setAttribute("uuid", pid);
%>
<c:url var="url" value="${kconfig.solrHost}/select/" >
<view:object name="mostDesirableViewObject" clz="cz.incad.Kramerius.views.inc.MostDesirableViewObject"></view:object>

<c:forEach items="${mostDesirableViewObject.pids}" var="uuid" varStatus="status">
<c:url var="url" value="${kConfigSolrHost}/select/" >
<c:param name="q" value="PID:\"${uuid}\"" />
</c:url>

<c:catch var="exceptions">
<c:import url="${url}" var="xml" charEncoding="UTF-8" />
</c:catch>
<c:choose>
<c:when test="${exceptions != null}">
<c:out value="${exceptions}" />
<c:out value="${xml}" />
</c:when>
<c:otherwise>
<c:catch var="exceptions">
<c:import url="${url}" var="xml" charEncoding="UTF-8" />
</c:catch>
<c:choose>
<c:when test="${exceptions != null}">
<c:out value="${exceptions}" />
<c:out value="${xml}" />
</c:when>
<c:otherwise>
<x:parse var="doc" xml="${xml}" />

<x:forEach varStatus="status" select="$doc/response/result/doc">
Expand All @@ -67,7 +51,9 @@
</div>
</x:forEach>

</c:otherwise>
</c:choose>
<%}%>
</c:otherwise>
</c:choose>

</c:forEach>

<div ><a href="inc/home/mostDesirables-rss.jsp"><span class="ui-icon ui-icon-signal-diag"></span></a></div>

0 comments on commit b18fe50

Please sign in to comment.