Search in sources :

Example 1 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class SearchServiceImplTest method testSearchForEpisodeWithSeriesMetadata.

/**
 * Tests whether an episode can be found based on its series metadata.
 */
@Test
public void testSearchForEpisodeWithSeriesMetadata() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-full.xml");
    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());
    SearchResult episodeMetadataResult = service.getByQuery(new SearchQuery().withText("Vegetation"));
    SearchResult seriesMetadataResult = service.getByQuery(new SearchQuery().withText("Atmospheric Science"));
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheric science")).size());
    assertEquals(1, episodeMetadataResult.getItems().length);
    assertEquals(1, seriesMetadataResult.getItems().length);
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResult(org.opencastproject.search.api.SearchResult) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 2 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class SearchServiceImplTest method testDeleteMediaPackage.

/**
 * Test removal from the search index.
 */
@Test
public void testDeleteMediaPackage() 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();
    // Now take the role away from the user
    userResponder.setResponse(userWithoutPermissions);
    Map<String, Integer> servers = new HashMap<String, Integer>();
    servers.put("http://localhost", 8080);
    organizationResponder.setResponse(new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, servers, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, null));
    // Try to 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());
    assertEquals("Unauthorized user was able to delete a mediapackage", Boolean.FALSE.toString(), job.getPayload());
    // Second try with a "fixed" roleset
    User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
    userResponder.setResponse(adminUser);
    Date deletedDate = new Date();
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Unauthorized user was able to delete a mediapackage", Job.Status.FINISHED, job.getStatus());
    // Now go back to the original security service and user
    userResponder.setResponse(defaultUser);
    organizationResponder.setResponse(defaultOrganization);
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/1");
    assertEquals(0, service.getByQuery(q).size());
    // Clear the ID requirement
    q.withId(null);
    assertEquals(0, service.getByQuery(q).size());
    q = new SearchQuery();
    q.withDeletedSince(deletedDate);
    assertEquals(1, service.getByQuery(q).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) JobBarrier(org.opencastproject.job.api.JobBarrier) Date(java.util.Date) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 3 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class SearchServiceImplTest method testSearchForPartialStrings.

@Test
public void testSearchForPartialStrings() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
    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());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmo")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmos")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosp")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosph")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosphe")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospher")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Vegetatio")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("vege")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("egetatio")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("egetation")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("lecture")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("lectur")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ecture")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ectur")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Science")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Scienc")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ience")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("cienc")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ducti")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Institute")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitute")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitut")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Institut")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("2008-03-05")).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 4 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class SeriesUpdatedEventHandler method handleEvent.

public void handleEvent(final SeriesItem seriesItem) {
    // A series or its ACL has been updated. Find any mediapackages with that series, and update them.
    logger.debug("Handling {}", seriesItem);
    String seriesId = seriesItem.getSeriesId();
    // We must be an administrative user to make this query
    final User prevUser = securityService.getUser();
    final Organization prevOrg = securityService.getOrganization();
    try {
        securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
        SearchQuery q = new SearchQuery().withSeriesId(seriesId);
        SearchResult result = searchService.getForAdministrativeRead(q);
        for (SearchResultItem item : result.getItems()) {
            MediaPackage mp = item.getMediaPackage();
            Organization org = organizationDirectoryService.getOrganization(item.getOrganization());
            securityService.setOrganization(org);
            // to the distribution channels as well
            if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
                // Build a new XACML file for this mediapackage
                Attachment fileRepoCopy = authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl()).getB();
                // Distribute the updated XACML file
                Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, fileRepoCopy.getIdentifier());
                JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
                Result jobResult = barrier.waitForJobs();
                if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
                    mp.remove(fileRepoCopy);
                    mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
                } else {
                    logger.error("Unable to distribute XACML {}", fileRepoCopy.getIdentifier());
                    continue;
                }
            }
            // Update the series dublin core
            if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
                DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
                mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
                // Update the series dublin core
                Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
                if (seriesCatalogs.length == 1) {
                    Catalog c = seriesCatalogs[0];
                    String filename = FilenameUtils.getName(c.getURI().toString());
                    URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
                    c.setURI(uri);
                    // setting the URI to a new source so the checksum will most like be invalid
                    c.setChecksum(null);
                    // Distribute the updated series dc
                    Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, c.getIdentifier());
                    JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
                    Result jobResult = barrier.waitForJobs();
                    if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
                        mp.remove(c);
                        mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
                    } else {
                        logger.error("Unable to distribute series catalog {}", c.getIdentifier());
                        continue;
                    }
                }
            }
            // Remove the series catalog and isPartOf from episode catalog
            if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
                mp.setSeries(null);
                mp.setSeriesTitle(null);
                boolean retractSeriesCatalog = retractSeriesCatalog(mp);
                boolean updateEpisodeCatalog = updateEpisodeCatalog(mp);
                if (!retractSeriesCatalog || !updateEpisodeCatalog)
                    continue;
            }
            // Update the search index with the modified mediapackage
            Job searchJob = searchService.add(mp);
            JobBarrier barrier = new JobBarrier(null, serviceRegistry, searchJob);
            barrier.waitForJobs();
        }
    } catch (SearchException e) {
        logger.warn("Unable to find mediapackages in search: ", e.getMessage());
    } catch (UnauthorizedException e) {
        logger.warn(e.getMessage());
    } catch (MediaPackageException e) {
        logger.warn(e.getMessage());
    } catch (ServiceRegistryException e) {
        logger.warn(e.getMessage());
    } catch (NotFoundException e) {
        logger.warn(e.getMessage());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    } catch (DistributionException e) {
        logger.warn(e.getMessage());
    } finally {
        securityService.setOrganization(prevOrg);
        securityService.setUser(prevUser);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SearchResultItem(org.opencastproject.search.api.SearchResultItem) SearchException(org.opencastproject.search.api.SearchException) NotFoundException(org.opencastproject.util.NotFoundException) SearchResult(org.opencastproject.search.api.SearchResult) Attachment(org.opencastproject.mediapackage.Attachment) IOException(java.io.IOException) JobBarrier(org.opencastproject.job.api.JobBarrier) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Result(org.opencastproject.job.api.JobBarrier.Result) SearchResult(org.opencastproject.search.api.SearchResult) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 5 with JobBarrier

use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.

the class SeriesUpdatedEventHandler method retractSeriesCatalog.

private boolean retractSeriesCatalog(MediaPackage mp) throws DistributionException {
    // Retract the series catalog
    for (Catalog c : mp.getCatalogs(MediaPackageElements.SERIES)) {
        Job retractJob = distributionService.retract(CHANNEL_ID, mp, c.getIdentifier());
        JobBarrier barrier = new JobBarrier(null, serviceRegistry, retractJob);
        Result jobResult = barrier.waitForJobs();
        if (jobResult.getStatus().get(retractJob).equals(FINISHED)) {
            mp.remove(c);
        } else {
            logger.error("Unable to retract series catalog {}", c.getIdentifier());
            return false;
        }
    }
    return true;
}
Also used : Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Result(org.opencastproject.job.api.JobBarrier.Result) SearchResult(org.opencastproject.search.api.SearchResult)

Aggregations

Job (org.opencastproject.job.api.Job)30 JobBarrier (org.opencastproject.job.api.JobBarrier)30 Test (org.junit.Test)24 MediaPackage (org.opencastproject.mediapackage.MediaPackage)11 SearchQuery (org.opencastproject.search.api.SearchQuery)10 NotFoundException (org.opencastproject.util.NotFoundException)7 Catalog (org.opencastproject.mediapackage.Catalog)6 SearchResult (org.opencastproject.search.api.SearchResult)6 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)6 PropertyVetoException (java.beans.PropertyVetoException)5 File (java.io.File)5 Hashtable (java.util.Hashtable)5 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)5 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 MediaInspectionException (org.opencastproject.inspection.api.MediaInspectionException)3 Result (org.opencastproject.job.api.JobBarrier.Result)3 AudioStream (org.opencastproject.mediapackage.AudioStream)3