Package org.fao.geonet.repository.statistic

Examples of org.fao.geonet.repository.statistic.SearchRequestRepository


       
        ISODate dateFrom = null;
        ISODate dateTo = null;

        Element elResp = new Element(Jeeves.Elem.RESPONSE);
        final SearchRequestRepository requestRepository = context.getBean(SearchRequestRepository.class);

        try {
            dateFrom = new ISODate(dateFromParam);
            dateTo = new ISODate(dateToParam);

            // TODO : if ByServiceType
            if (byType) {
                final List<String> serviceTypes = requestRepository.selectAllDistinctAttributes(SearchRequest_
                        .service);
                for (String serviceType : serviceTypes) {
                    Element results = buildQuery(requestRepository, serviceType, dateFrom, dateTo, graphicType);

                    results.setAttribute("service", serviceType);
                    elResp.addContent(results);
                }
            } else {
                Element results = buildQuery(requestRepository, null, dateFrom, dateTo, graphicType);
                elResp.addContent(results);
            }

            elResp.addContent(new Element("dateFrom").setText(dateFrom.getDateAndTime()));
            elResp.addContent(new Element("dateTo").setText(dateTo.getDateAndTime()));
        } catch (Exception e) {
            elResp.setAttribute("error", e.getMessage());
        }

        final ISODate oldestRequestDate = requestRepository.getOldestRequestDate();
        SearchStatistics.addSingleDBValueToElement(elResp,
                oldestRequestDate,
                "dateMin", "min");
        final ISODate mostRecentRequestDate = requestRepository.getMostRecentRequestDate();
        SearchStatistics.addSingleDBValueToElement(elResp,
                mostRecentRequestDate ,
                "dateMax", "max");

        return elResp;
View Full Code Here


    @Override
    public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception {
        String service = Util.getParam(params, SERVICE_PARAM);
        Element response = new Element("response");

        final SearchRequestRepository requestRepository = context.getBean(SearchRequestRepository.class);

        ISODate begin = requestRepository.getOldestRequestDate();
        ISODate end = requestRepository.getMostRecentRequestDate();
        if (begin == null || end == null) {
            return response;    // No stats available.
        }
        DateTime beginDate = ISODate.parseBasicOrFullDateTime(begin.getDateAndTime());
        DateTime endDate = ISODate.parseBasicOrFullDateTime(end.getDateAndTime());
        int days = Days.daysBetween(beginDate, endDate).getDays();
        int nonZeroDays = days == 0 ? 1 : days;
        int months = Months.monthsBetween(beginDate, endDate).getMonths();
        int nonZeroMonths = months == 0 ? 1 : months;
        response.addContent(new Element("activity_days").setText(days + ""));
        response.addContent(new Element("activity_months").setText(months + ""));


        // Total number of searches
        long total = requestRepository.count(hasService(service));
        addSingleDBValueToElement(response, total, "total_searches", "total");

        // Average searches by day
        long avgPerDay = total / nonZeroDays;
        addSingleDBValueToElement(response, avgPerDay, "avg_searches_by_day", "avg");

        // Average searches by month
        long avgPerMonth = total / nonZeroMonths;
        addSingleDBValueToElement(response, avgPerMonth, "avg_searches_by_month", "avg");

        // Average views by day
        final int views = context.getBean(MetadataRepository.class).getMetadataStatistics().getTotalStat(popularitySum(),
                Optional.<Specification<Metadata>>absent());
        int viewsByDay = views / nonZeroDays;
        addSingleDBValueToElement(response, viewsByDay, "avg_views_by_day", "avg");

        // Average views by month
        int viewsByMonth = views / nonZeroMonths;
        addSingleDBValueToElement(response, viewsByMonth, "avg_views_by_month", "avg");

        // Number of search with no hits
        long noHits = requestRepository.count(where(hasService(service)).and(hasHits(0)));
        addSingleDBValueToElement(response, noHits, "total_searches_with_no_hits", "total");

        return response;
    }
View Full Code Here

   * Stores this object to.
   * @param context
   * @return
   */
    public boolean storeToDb(ServiceContext context) {
        SearchRequestRepository requestRepo = context.getBean(SearchRequestRepository.class);
        // prepares a transaction to log all or nothing into database.

        //Connection con = null;
        //--- generate a new metadata id
        SearchRequest request = new SearchRequest();
        request.setAutogenerated(this.autoGenQuery);
        request.setHits(this.hits);
        request.setIpAddress(this.ip);
        request.setLang(this.language);
        request.setLuceneQuery(this.luceneQuery);
        request.setMetadataType(this.mdType.name());
        request.setRequestDate(new ISODate(this.date.getTime(), false));
        request.setService(this.service);
        request.setSimple(this.isSimpleQuery());
        request.setSortBy(this.sortBy);
        request.setSpatialFilter(this.spatialFilter);

        // stores each QueryInfo object into the database
        if (this.queryInfos != null && !this.autoGenQuery) {
            request.addAll(this.queryInfos);
        } else {
            if (this.autoGenQuery) {
                if (Log.isDebugEnabled(Geonet.SEARCH_LOGGER)) {
                    Log.debug(Geonet.SEARCH_LOGGER, "Guiservice/autogenerated query not inserted into database: " + this.luceneQuery);
                }
            } else {
                if (Log.isDebugEnabled(Geonet.SEARCH_LOGGER)) {
                    Log.debug(Geonet.SEARCH_LOGGER, "No queryInfo objects to insert into database for this query: " + this.luceneQuery);
                }
            }
        }

        requestRepo.save(request);
        if (Log.isDebugEnabled(Geonet.SEARCH_LOGGER))
            Log.debug(Geonet.SEARCH_LOGGER, "QueryRequest inserted (id: " + this.requestId + ")");
        return true;
    }
View Full Code Here

TOP

Related Classes of org.fao.geonet.repository.statistic.SearchRequestRepository

Copyright © 2018 www.massapicom. 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.