Search in sources :

Example 16 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class SearchServiceImplTest method testAddSeriesMediaPackage.

/**
 * Adds a media package with a dublin core catalog for episode and series. Verifies series catalog can be retrieved
 * via search service.
 */
@Test
public void testAddSeriesMediaPackage() throws Exception {
    String seriesId = "foobar-series";
    MediaPackage mediaPackage = getMediaPackage("/manifest-full.xml");
    mediaPackage.setSeries(seriesId);
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
    User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
    userResponder.setResponse(adminUser);
    // Make sure it's properly indexed and returned
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(false);
    q.includeSeries(true);
    SearchResult result = service.getByQuery(q);
    assertEquals(1, result.size());
    assertEquals(seriesId, result.getItems()[0].getId());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JaxbUser(org.opencastproject.security.api.JaxbUser) SearchResult(org.opencastproject.search.api.SearchResult) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 17 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class SearchServiceImplTest method testAddFullMediaPackage.

/**
 * Ads a simple media package that has a dublin core for the episode only.
 */
@Test
public void testAddFullMediaPackage() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-full.xml");
    // Make sure our mocked ACL has the read and write permission
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
    // Make sure it's properly indexed and returned
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/2");
    assertEquals(1, service.getByQuery(q).size());
    // Clear the ID requirement
    q.withId(null);
    assertEquals(1, service.getByQuery(q).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 18 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class SearchServiceImplTest method testDeleteIndexNotInDbMediaPackage.

/**
 * Test removal from the search index even when it is missing from database #MH-11616
 */
@Test
public void testDeleteIndexNotInDbMediaPackage() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
    // Make sure our mocked ACL has the read and write permission
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    // Delete the mediapackage from persistence (leave it in index)
    Date dateDeletedFromDb = new Date();
    searchDatabase.deleteMediaPackage(mediaPackage.getIdentifier().toString(), dateDeletedFromDb);
    // Verify it is not marked as deleted
    SearchQuery qDel = new SearchQuery();
    qDel.withDeletedSince(dateDeletedFromDb);
    assertEquals(0, service.getByQuery(qDel).size());
    // Verify that it is still active in index
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId(mediaPackage.getIdentifier().toString());
    assertEquals(1, service.getByQuery(q).size());
    // Try delete it
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
    // Verify that it is now not active in the index
    assertEquals(0, service.getByQuery(q).size());
    // Verify that it is now marked as deleted in the index
    q = new SearchQuery();
    q.withDeletedSince(dateDeletedFromDb);
    assertEquals(1, service.getByQuery(q).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Date(java.util.Date) Test(org.junit.Test)

Example 19 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class SearchServiceImplTest method testEmptySearchIndex.

/**
 * Test whether an empty search index will work.
 */
@Test
public void testEmptySearchIndex() {
    SearchResult result = service.getByQuery(new SearchQuery().withId("foo"));
    assertEquals(0, result.size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchResult(org.opencastproject.search.api.SearchResult) Test(org.junit.Test)

Example 20 with SearchQuery

use of org.opencastproject.search.api.SearchQuery in project opencast by opencast.

the class SearchServiceImplTest method testAddSimpleMediaPackage.

/**
 * Adds a simple media package that has a dublin core for the episode only.
 */
@Test
public void testAddSimpleMediaPackage() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
    // Make sure our mocked ACL has the read and write permission
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
    // Make sure it's properly indexed and returned
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/1");
    assertEquals(1, service.getByQuery(q).size());
    q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    assertEquals(1, service.getByQuery(q).size());
    // Test for various fields
    q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/1");
    SearchResult result = service.getByQuery(q);
    assertEquals(1, result.getTotalSize());
    SearchResultItem resultItem = result.getItems()[0];
    assertNotNull(resultItem.getMediaPackage());
    assertEquals(1, resultItem.getMediaPackage().getCatalogs().length);
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResultItem(org.opencastproject.search.api.SearchResultItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) SearchResult(org.opencastproject.search.api.SearchResult) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Aggregations

SearchQuery (org.opencastproject.search.api.SearchQuery)25 MediaPackage (org.opencastproject.mediapackage.MediaPackage)14 Job (org.opencastproject.job.api.Job)12 Test (org.junit.Test)11 JobBarrier (org.opencastproject.job.api.JobBarrier)10 SearchResult (org.opencastproject.search.api.SearchResult)10 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 User (org.opencastproject.security.api.User)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)3 SearchException (org.opencastproject.search.api.SearchException)2 SearchResultItem (org.opencastproject.search.api.SearchResultItem)2 JaxbRole (org.opencastproject.security.api.JaxbRole)2 JaxbUser (org.opencastproject.security.api.JaxbUser)2