Package org.dspace.xoai.filter

Source Code of org.dspace.xoai.filter.DateUntilFilter

/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.xoai.filter;

import com.lyncode.builder.DateBuilder;
import com.lyncode.xoai.dataprovider.services.api.DateProvider;
import com.lyncode.xoai.dataprovider.services.impl.BaseDateProvider;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.dspace.core.Context;
import org.dspace.xoai.data.DSpaceItem;
import org.dspace.xoai.filter.results.DatabaseFilterResult;
import org.dspace.xoai.filter.results.SolrFilterResult;

import java.util.Date;

/**
*
* @author Lyncode Development Team <dspace@lyncode.com>
*/
public class DateUntilFilter extends DSpaceFilter
{
    private static DateProvider dateProvider = new BaseDateProvider();
    private Date date;

    public DateUntilFilter(Date date)
    {
        this.date = new DateBuilder(date).setMaxMilliseconds().build();
    }

    @Override
    public DatabaseFilterResult buildDatabaseQuery(Context context)
    {
        return new DatabaseFilterResult("i.last_modified <= ?", new java.sql.Date(date.getTime()));
    }

    @Override
    public boolean isShown(DSpaceItem item)
    {
        if (item.getDatestamp().compareTo(date) <= 0)
            return true;
        return false;
    }

    @Override
    public SolrFilterResult buildSolrQuery()
    {
        String format = dateProvider.format(date).replace("Z", ".999Z"); // Tweak to set the millisecon
        return new SolrFilterResult("item.lastmodified:[* TO "
                + ClientUtils.escapeQueryChars(format) + "]");
    }

}
TOP

Related Classes of org.dspace.xoai.filter.DateUntilFilter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.