Search in sources :

Example 6 with SeriesQuery

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

the class SeriesServiceSolrIndex method queryIdTitleMap.

@Override
public Map<String, String> queryIdTitleMap() throws SeriesServiceDatabaseException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setStart(0);
    solrQuery.setRows(Integer.MAX_VALUE);
    solrQuery.setQuery(buildSolrQueryString(new SeriesQuery(), false));
    solrQuery.addSortField(getSortField(SeriesQuery.Sort.TITLE) + "_sort", SolrQuery.ORDER.asc);
    Map<String, String> result;
    try {
        QueryResponse response = solrServer.query(solrQuery);
        SolrDocumentList items = response.getResults();
        result = new HashMap<String, String>();
        for (SolrDocument doc : items) {
            String seriesId = getSeriesIDfromCompositeID((String) doc.get(SolrFields.COMPOSITE_ID_KEY), securityService.getOrganization().getId());
            String seriesTitle = (String) doc.get(SolrFields.TITLE_KEY);
            result.put(seriesId, seriesTitle);
        }
        return result;
    } catch (Exception e) {
        logger.error("Could not retrieve results: {}", e.getMessage());
        throw new SeriesServiceDatabaseException(e);
    }
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 7 with SeriesQuery

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

the class SeriesServiceRemoteImpl method getSeries.

// CHECKSTYLE:OFF
private SeriesQuery 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 isFuzzyMatch) 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());
    }
    // allow seriesId wild card search
    if (isFuzzyMatch != null) {
        q.setFuzzyMatch(isFuzzyMatch.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 q;
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) ParseException(java.text.ParseException)

Example 8 with SeriesQuery

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

the class SeriesServiceImplTest method testSeriesQuery.

@Test
public void testSeriesQuery() throws Exception {
    testCatalog.set(DublinCore.PROPERTY_TITLE, "Some title");
    seriesService.updateSeries(testCatalog);
    SeriesQuery q = new SeriesQuery().setSeriesTitle("other");
    List<DublinCoreCatalog> result = seriesService.getSeries(q).getCatalogList();
    Assert.assertEquals(0, result.size());
    testCatalog.set(DublinCore.PROPERTY_TITLE, "Some other title");
    seriesService.updateSeries(testCatalog);
    result = seriesService.getSeries(q).getCatalogList();
    Assert.assertEquals(1, result.size());
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Test(org.junit.Test)

Example 9 with SeriesQuery

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

the class SeriesServiceSolrTest method testCreatedRangedTest.

@Test
public void testCreatedRangedTest() throws Exception {
    DublinCoreCatalog firstCatalog = dcService.newInstance();
    firstCatalog.add(DublinCore.PROPERTY_IDENTIFIER, "10.0000/1");
    firstCatalog.add(DublinCore.PROPERTY_TITLE, "Cats and Dogs");
    firstCatalog.add(DublinCore.PROPERTY_CREATED, "2007-05-03");
    DublinCoreCatalog secondCatalog = dcService.newInstance();
    secondCatalog.add(DublinCore.PROPERTY_IDENTIFIER, "10.0000/2");
    secondCatalog.add(DublinCore.PROPERTY_TITLE, "Nature of Dogs");
    secondCatalog.add(DublinCore.PROPERTY_CREATED, "2007-05-05");
    DublinCoreCatalog thirdCatalog = dcService.newInstance();
    thirdCatalog.add(DublinCore.PROPERTY_IDENTIFIER, "10.0000/3");
    thirdCatalog.add(DublinCore.PROPERTY_TITLE, "Nature");
    thirdCatalog.add(DublinCore.PROPERTY_CREATED, "2007-05-07");
    index.updateIndex(firstCatalog);
    index.updateIndex(secondCatalog);
    index.updateIndex(thirdCatalog);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SeriesQuery q = new SeriesQuery().setCreatedFrom(sdf.parse("2007-05-02")).setCreatedTo(sdf.parse("2007-05-06"));
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("Two series satisfy time range", result.size() == 2);
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 10 with SeriesQuery

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

the class SeriesServiceSolrTest method testSearchingByTitleAndFullText.

@Test
public void testSearchingByTitleAndFullText() throws Exception {
    DublinCoreCatalog firstCatalog = dcService.newInstance();
    firstCatalog.add(DublinCore.PROPERTY_IDENTIFIER, "10.0000/1");
    firstCatalog.add(DublinCore.PROPERTY_TITLE, "Cats and Dogs");
    firstCatalog.add(DublinCore.PROPERTY_DESCRIPTION, "This lecture tries to give an explanation...");
    DublinCoreCatalog secondCatalog = dcService.newInstance();
    secondCatalog.add(DublinCore.PROPERTY_IDENTIFIER, "10.0000/2");
    secondCatalog.add(DublinCore.PROPERTY_TITLE, "Nature of Dogs");
    secondCatalog.add(DublinCore.PROPERTY_DESCRIPTION, "Why do dogs chase cats?");
    index.updateIndex(firstCatalog);
    index.updateIndex(secondCatalog);
    SeriesQuery q = new SeriesQuery().setSeriesTitle("cat");
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("Only one title contains 'cat'", result.size() == 1);
    q = new SeriesQuery().setSeriesTitle("dog");
    result = index.search(q);
    Assert.assertTrue("Both titles contains 'dog'", result.size() == 2);
    q = new SeriesQuery().setText("cat");
    result = index.search(q);
    Assert.assertTrue("Both Dublin Cores contains 'cat'", result.size() == 2);
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Test(org.junit.Test)

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