Search in sources :

Example 1 with SeriesQuery

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

the class SeriesListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> series = new HashMap<String, String>();
    SeriesQuery q = new SeriesQuery().setCount(Integer.MAX_VALUE);
    if (query != null) {
        if (query.hasFilter(FILTER_TEXT)) {
            StringListFilter filter = (StringListFilter) query.getFilter(FILTER_TEXT);
            if (filter.getValue().isSome())
                q.setText(filter.getValue().get());
        }
        if (query.getLimit().isSome())
            q.setCount(query.getLimit().get());
        if (query.getOffset().isSome())
            q.setStartPage(query.getOffset().get());
    }
    List<DublinCoreCatalog> result = null;
    try {
        if (!CONTRIBUTORS.equals(listName) && !ORGANIZERS.equals(listName) && !TITLE_EXTENDED.equals(listName)) {
            return seriesService.getIdTitleMapOfAllSeries();
        }
        result = seriesService.getSeries(q).getCatalogList();
    } catch (SeriesException e) {
        throw new ListProviderException("Error appends on the series service: " + e);
    } catch (UnauthorizedException e) {
        throw new ListProviderException("Unauthorized access to series service: " + e);
    }
    for (DublinCoreCatalog dc : result) {
        if (CONTRIBUTORS.equals(listName)) {
            String contributor = dc.getFirst(DublinCore.PROPERTY_CONTRIBUTOR);
            if (StringUtils.isNotBlank(contributor))
                series.put(contributor, contributor);
        } else if (ORGANIZERS.equals(listName)) {
            String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
            if (StringUtils.isNotBlank(organizer))
                series.put(organizer, organizer);
        } else if (TITLE_EXTENDED.equals(listName)) {
            String created = dc.getFirst(DublinCoreCatalog.PROPERTY_CREATED);
            String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
            StringBuilder sb = new StringBuilder(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
            if (StringUtils.isNotBlank(created) && StringUtils.isNotBlank(organizer)) {
                List<String> extendedTitleData = new ArrayList<>();
                if (StringUtils.isNotBlank(created)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(EncodingSchemeUtils.decodeDate(created));
                    extendedTitleData.add(Integer.toString(calendar.get(Calendar.YEAR)));
                }
                if (StringUtils.isNotBlank(organizer))
                    extendedTitleData.add(organizer);
                sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
            }
            series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), sb.toString());
        } else {
            series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
        }
    }
    return series;
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter)

Example 2 with SeriesQuery

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

the class SeriesServiceRemoteImpl method getSeriesAsJson.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("series.json")
@RestQuery(name = "listSeriesAsJson", description = "Returns the series matching the query parameters", returnDescription = "Returns the series search results as JSON", restParameters = { @RestParameter(name = "q", isRequired = false, description = "Free text search", type = STRING), @RestParameter(name = "edit", isRequired = false, description = "Whether this query should return only series that are editable", type = BOOLEAN), @RestParameter(name = "fuzzyMatch", isRequired = false, description = "Whether a partial match on series id is allowed, default is false", type = BOOLEAN), @RestParameter(name = "seriesId", isRequired = false, description = "The series identifier", type = STRING), @RestParameter(name = "seriesTitle", isRequired = false, description = "The series title", type = STRING), @RestParameter(name = "creator", isRequired = false, description = "The series creator", type = STRING), @RestParameter(name = "contributor", isRequired = false, description = "The series contributor", type = STRING), @RestParameter(name = "publisher", isRequired = false, description = "The series publisher", type = STRING), @RestParameter(name = "rightsholder", isRequired = false, description = "The series rights holder", type = STRING), @RestParameter(name = "createdfrom", isRequired = false, description = "Filter results by created from (yyyy-MM-dd'T'HH:mm:ss'Z')", type = STRING), @RestParameter(name = "createdto", isRequired = false, description = "Filter results by created to (yyyy-MM-dd'T'HH:mm:ss'Z')", type = STRING), @RestParameter(name = "language", isRequired = false, description = "The series language", type = STRING), @RestParameter(name = "license", isRequired = false, description = "The series license", type = STRING), @RestParameter(name = "subject", isRequired = false, description = "The series subject", type = STRING), @RestParameter(name = "abstract", isRequired = false, description = "The series abstract", type = STRING), @RestParameter(name = "description", isRequired = false, description = "The series description", type = STRING), @RestParameter(name = "sort", isRequired = false, description = "The sort order.  May include any of the following: TITLE, SUBJECT, CREATOR, PUBLISHER, CONTRIBUTOR, ABSTRACT, DESCRIPTION, CREATED, AVAILABLE_FROM, AVAILABLE_TO, LANGUAGE, RIGHTS_HOLDER, SPATIAL, TEMPORAL, IS_PART_OF, REPLACES, TYPE, ACCESS, LICENCE.  Add '_DESC' to reverse the sort order (e.g. TITLE_DESC).", type = STRING), @RestParameter(name = "startPage", isRequired = false, description = "The page offset", type = STRING), @RestParameter(name = "count", isRequired = false, description = "Results per page (max 100)", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public // CHECKSTYLE:OFF
Response getSeriesAsJson(@QueryParam("q") String text, @QueryParam("seriesId") String seriesId, @QueryParam("edit") Boolean edit, @QueryParam("fuzzyMatch") Boolean fuzzyMatch, @QueryParam("seriesTitle") String seriesTitle, @QueryParam("creator") String creator, @QueryParam("contributor") String contributor, @QueryParam("publisher") String publisher, @QueryParam("rightsholder") String rightsHolder, @QueryParam("createdfrom") String createdFrom, @QueryParam("createdto") String createdTo, @QueryParam("language") String language, @QueryParam("license") String license, @QueryParam("subject") String subject, @QueryParam("abstract") String seriesAbstract, @QueryParam("description") String description, @QueryParam("sort") String sort, @QueryParam("startPage") String startPage, @QueryParam("count") String count) throws UnauthorizedException {
    // CHECKSTYLE:ON
    try {
        SeriesQuery seriesQuery = getSeries(text, seriesId, edit, seriesTitle, creator, contributor, publisher, rightsHolder, createdFrom, createdTo, language, license, subject, seriesAbstract, description, sort, startPage, count, fuzzyMatch);
        DublinCoreCatalogList result = getSeries(seriesQuery);
        return Response.ok(result.getResultsAsJson()).build();
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Could not perform search query: {}", e.getMessage());
    }
    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with SeriesQuery

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

the class SeriesServiceImplTest method testSeriesFuzzyIdSearchQuery.

@Test
public void testSeriesFuzzyIdSearchQuery() throws Exception {
    testCatalog.set(DublinCore.PROPERTY_IDENTIFIER, "20160119999");
    seriesService.updateSeries(testCatalog);
    SeriesQuery q = new SeriesQuery().setSeriesId("201601");
    q.setFuzzyMatch(true);
    List<DublinCoreCatalog> 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 4 with SeriesQuery

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

the class SeriesServiceSolrTest method testAccessControlManagmentRewrite.

@Test
public void testAccessControlManagmentRewrite() throws Exception {
    // sample access control list
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    User user = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole("ROLE_ANONYMOUS", new DefaultOrganization()));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    // deactivate the default index created in setUp()
    index.deactivate();
    // create a new index with the security service anonymous user
    index = new SeriesServiceSolrIndex();
    index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
    dcService = new DublinCoreCatalogService();
    index.setDublinCoreService(dcService);
    index.setSecurityService(securityService);
    index.activate(null);
    AccessControlList accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("ROLE_ANONYMOUS", Permissions.Action.READ.toString(), true));
    index.updateIndex(testCatalog);
    String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    index.updateSecurityPolicy(seriesID, accessControlList);
    SeriesQuery q = new SeriesQuery();
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("Only one anomymous series", result.size() == 1);
    index.updateSecurityPolicy(seriesID, new AccessControlList());
    q = new SeriesQuery();
    result = index.search(q);
    Assert.assertTrue("No anomymous series", result.size() == 0);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 5 with SeriesQuery

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

the class SeriesServiceSolrTest method testSpecialOrgId.

@Test
public void testSpecialOrgId() throws Exception {
    String seriesId = "09157c61-d886-4b4a-a7b1-48da8618e780";
    DublinCoreCatalog firstCatalog = dcService.newInstance();
    firstCatalog.add(DublinCore.PROPERTY_IDENTIFIER, seriesId);
    firstCatalog.add(DublinCore.PROPERTY_TITLE, "Cats and Dogs");
    firstCatalog.add(DublinCore.PROPERTY_CREATED, "2007-05-03");
    index.updateIndex(firstCatalog);
    SeriesQuery q = new SeriesQuery().setSeriesId(seriesId);
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("One series satisfy id", result.size() == 1);
    Assert.assertEquals(1, index.count());
    index.delete(seriesId);
    result = index.search(q);
    Assert.assertTrue("No series satisfy id", result.size() == 0);
    Assert.assertEquals(0, index.count());
}
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