Search in sources :

Example 11 with SeriesQuery

use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.

the class SeriesRestService method getSeries.

// CHECKSTYLE:OFF
private DublinCoreCatalogList getSeries(String text, String seriesId, Boolean edit, String seriesTitle, String creator, String contributor, String publisher, String rightsHolder, String createdFrom, String createdTo, String language, String license, String subject, String seriesAbstract, String description, String sort, String startPageString, String countString, Boolean fuzzyMatch) throws SeriesException, UnauthorizedException {
    // CHECKSTYLE:ON
    int startPage = 0;
    if (StringUtils.isNotEmpty(startPageString)) {
        try {
            startPage = Integer.parseInt(startPageString);
        } catch (NumberFormatException e) {
            logger.warn("Bad start page parameter");
        }
        if (startPage < 0) {
            startPage = 0;
        }
    }
    int count = DEFAULT_LIMIT;
    if (StringUtils.isNotEmpty(countString)) {
        try {
            count = Integer.parseInt(countString);
        } catch (NumberFormatException e) {
            logger.warn("Bad count parameter");
        }
        if (count < 1)
            count = DEFAULT_LIMIT;
    }
    SeriesQuery q = new SeriesQuery();
    q.setCount(count);
    q.setStartPage(startPage);
    if (edit != null) {
        q.setEdit(edit);
    }
    if (StringUtils.isNotEmpty(text)) {
        q.setText(text.toLowerCase());
    }
    if (StringUtils.isNotEmpty(seriesId)) {
        q.setSeriesId(seriesId.toLowerCase());
    }
    if (StringUtils.isNotEmpty(seriesTitle)) {
        q.setSeriesTitle(seriesTitle.toLowerCase());
    }
    if (StringUtils.isNotEmpty(creator)) {
        q.setCreator(creator.toLowerCase());
    }
    if (StringUtils.isNotEmpty(contributor)) {
        q.setContributor(contributor.toLowerCase());
    }
    if (StringUtils.isNotEmpty(language)) {
        q.setLanguage(language.toLowerCase());
    }
    if (StringUtils.isNotEmpty(license)) {
        q.setLicense(license.toLowerCase());
    }
    if (StringUtils.isNotEmpty(subject)) {
        q.setSubject(subject.toLowerCase());
    }
    if (StringUtils.isNotEmpty(publisher)) {
        q.setPublisher(publisher.toLowerCase());
    }
    if (StringUtils.isNotEmpty(seriesAbstract)) {
        q.setSeriesAbstract(seriesAbstract.toLowerCase());
    }
    if (StringUtils.isNotEmpty(description)) {
        q.setDescription(description.toLowerCase());
    }
    if (StringUtils.isNotEmpty(rightsHolder)) {
        q.setRightsHolder(rightsHolder.toLowerCase());
    }
    if (fuzzyMatch != null) {
        q.setFuzzyMatch(fuzzyMatch.booleanValue());
    }
    try {
        if (StringUtils.isNotEmpty(createdFrom)) {
            q.setCreatedFrom(SolrUtils.parseDate(createdFrom));
        }
        if (StringUtils.isNotEmpty(createdTo)) {
            q.setCreatedTo(SolrUtils.parseDate(createdTo));
        }
    } catch (ParseException e1) {
        logger.warn("Could not parse date parameter: {}", e1);
    }
    if (StringUtils.isNotBlank(sort)) {
        SeriesQuery.Sort sortField = null;
        if (sort.endsWith("_DESC")) {
            String enumKey = sort.substring(0, sort.length() - "_DESC".length()).toUpperCase();
            try {
                sortField = SeriesQuery.Sort.valueOf(enumKey);
                q.withSort(sortField, false);
            } catch (IllegalArgumentException e) {
                logger.warn("No sort enum matches '{}'", enumKey);
            }
        } else {
            try {
                sortField = SeriesQuery.Sort.valueOf(sort);
                q.withSort(sortField);
            } catch (IllegalArgumentException e) {
                logger.warn("No sort enum matches '{}'", sort);
            }
        }
    }
    return seriesService.getSeries(q);
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) ParseException(java.text.ParseException)

Aggregations

SeriesQuery (org.opencastproject.series.api.SeriesQuery)11 Test (org.junit.Test)6 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)6 DublinCoreCatalogList (org.opencastproject.metadata.dublincore.DublinCoreCatalogList)5 ParseException (java.text.ParseException)3 SeriesException (org.opencastproject.series.api.SeriesException)3 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)2 NotFoundException (org.opencastproject.util.NotFoundException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1