diff --git a/common/src/main/java/cz/incad/kramerius/MostDesirable.java b/common/src/main/java/cz/incad/kramerius/MostDesirable.java index c83e08c425..3d16b9dee4 100644 --- a/common/src/main/java/cz/incad/kramerius/MostDesirable.java +++ b/common/src/main/java/cz/incad/kramerius/MostDesirable.java @@ -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 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 getMostDesirable(int count, int offset, String model); + } diff --git a/common/src/main/java/cz/incad/kramerius/impl/MostDesirableImpl.java b/common/src/main/java/cz/incad/kramerius/impl/MostDesirableImpl.java index f4416631ef..5eecafa617 100644 --- a/common/src/main/java/cz/incad/kramerius/impl/MostDesirableImpl.java +++ b/common/src/main/java/cz/incad/kramerius/impl/MostDesirableImpl.java @@ -7,9 +7,12 @@ 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; @@ -17,14 +20,17 @@ 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 provider; private FedoraAccess fedoraAccess; + @Inject public MostDesirableImpl( @Named("kramerius4") Provider provider, @@ -36,6 +42,10 @@ public MostDesirableImpl( @Override public List 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(provider.get(), true) { @Override @@ -44,7 +54,7 @@ public boolean handleRow(ResultSet rs, List 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(provider.get(), true) { @Override @@ -53,10 +63,13 @@ public boolean handleRow(ResultSet rs, List 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 { diff --git a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/AbstractPDFResource.java b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/AbstractPDFResource.java index 341eb7202f..ac30deb7fe 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/AbstractPDFResource.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/AbstractPDFResource.java @@ -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; @@ -99,6 +100,9 @@ public enum FirstPage { SimplePDFService simplePdfService; + @Inject + MostDesirable mostDesirable; + @GET @Path("conf") diff --git a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/PDFResource.java b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/PDFResource.java index ec159425c6..33d4f938d9 100644 --- a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/PDFResource.java +++ b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/pdf/PDFResource.java @@ -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); @@ -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); @@ -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; diff --git a/search/src/java/cz/incad/Kramerius/imaging/ZoomifyServlet.java b/search/src/java/cz/incad/Kramerius/imaging/ZoomifyServlet.java index 34b5ca8bb7..29c2f621b1 100644 --- a/search/src/java/cz/incad/Kramerius/imaging/ZoomifyServlet.java +++ b/search/src/java/cz/incad/Kramerius/imaging/ZoomifyServlet.java @@ -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; @@ -92,6 +93,9 @@ public class ZoomifyServlet extends AbstractImageServlet { @Inject SolrAccess solrAccess; + + @Inject + MostDesirable mostDesirable; @Override @@ -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 { diff --git a/search/src/java/cz/incad/Kramerius/views/inc/MostDesirableViewObject.java b/search/src/java/cz/incad/Kramerius/views/inc/MostDesirableViewObject.java new file mode 100644 index 0000000000..7e93bc4a0a --- /dev/null +++ b/search/src/java/cz/incad/Kramerius/views/inc/MostDesirableViewObject.java @@ -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 getPids() { + + List pids = new ArrayList(); + List 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 found = this.mostDesirable.getMostDesirable(NUMBER_OF_DESIRABLE_ITEMS, 0, model); + pids.addAll(found); + if (pids.size() >= NUMBER_OF_DESIRABLE_ITEMS) { + break; + } + } + return pids; + } +} diff --git a/search/web/inc/home/mostDesirables.jsp b/search/web/inc/home/mostDesirables.jsp index 03931c2d72..1c8ec16e99 100644 --- a/search/web/inc/home/mostDesirables.jsp +++ b/search/web/inc/home/mostDesirables.jsp @@ -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); + - FedoraAccess fedoraAccess = ctxInj.getInstance(com.google.inject.Key.get(FedoraAccess.class, com.google.inject.name.Names.named("securedFedoraAccess"))); - List uuids = (List)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); - %> - + + + + - - - - - - - - - - + + + + + + + + + @@ -67,7 +51,9 @@ - - -<%}%> + + + + +
\ No newline at end of file