Search in sources :

Example 1 with SearchResult

use of org.opencastproject.search.api.SearchResult 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 SearchResult

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

the class SeriesFeedService method accept.

/**
 * @see org.opencastproject.feed.api.FeedGenerator#accept(java.lang.String[])
 */
@Override
public boolean accept(String[] query) {
    boolean generalChecksPassed = super.accept(query);
    if (!generalChecksPassed)
        return false;
    // Build the series id, first parameter is the selector. Note that if the series identifier
    // contained slashes (e. g. in the case of a handle or doi), we need to reassemble the
    // identifier
    StringBuffer sId = new StringBuffer();
    int idparts = query.length - 1;
    if (idparts < 1)
        return false;
    for (int i = 1; i <= idparts; i++) {
        if (sId.length() > 0)
            sId.append("/");
        sId.append(query[i]);
    }
    // Remember the series id
    final String seriesId = sId.toString();
    series.set(seriesId);
    try {
        // To check if we can accept the query it is enough to query for just one result
        // Check the series service to see if the series exists
        // but has not yet had anything published from it
        Object result = seriesCache.getUnchecked(seriesId);
        if (result == nullToken)
            return false;
        SearchResult searchResult = (SearchResult) result;
        seriesData.set(searchResult);
        return searchResult.size() > 0;
    } catch (Exception e) {
        return false;
    }
}
Also used : SearchResult(org.opencastproject.search.api.SearchResult)

Example 3 with SearchResult

use of org.opencastproject.search.api.SearchResult 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 4 with SearchResult

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

the class LiveScheduleServiceImplTest method testGetMediaPackageFromSearch.

@Test
public void testGetMediaPackageFromSearch() throws Exception {
    URI searchResultURI = LiveScheduleServiceImplTest.class.getResource("/search-result.xml").toURI();
    SearchResult searchResult = SearchResultImpl.valueOf(searchResultURI.toURL().openStream());
    EasyMock.expect(searchService.getByQuery((SearchQuery) EasyMock.anyObject())).andReturn(searchResult);
    replayServices();
    MediaPackage mp = service.getMediaPackageFromSearch(MP_ID);
    Assert.assertNotNull(mp);
    Assert.assertEquals(MP_ID, mp.getIdentifier().compact());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResult(org.opencastproject.search.api.SearchResult) URI(java.net.URI) Test(org.junit.Test)

Example 5 with SearchResult

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

the class LiveScheduleServiceImpl method getMediaPackageFromSearch.

/**
 * Retrieves the media package from the search index.
 *
 * @param mediaPackageId
 *          the media package id
 * @return the media package in the search index or null if not there
 * @throws LiveException
 *           if found many media packages with the same id
 */
MediaPackage getMediaPackageFromSearch(String mediaPackageId) throws LiveScheduleException {
    // Look for the media package in the search index
    SearchQuery query = new SearchQuery().withId(mediaPackageId);
    SearchResult result = searchService.getByQuery(query);
    if (result.size() == 0) {
        logger.debug("The search service doesn't know live mediapackage {}", mediaPackageId);
        return null;
    } else if (result.size() > 1) {
        logger.warn("More than one live mediapackage with id {} returned from search service", mediaPackageId);
        throw new LiveScheduleException("More than one live mediapackage with id " + mediaPackageId + " found");
    }
    return result.getItems()[0].getMediaPackage();
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchResult(org.opencastproject.search.api.SearchResult) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException)

Aggregations

SearchResult (org.opencastproject.search.api.SearchResult)15 SearchQuery (org.opencastproject.search.api.SearchQuery)10 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 Test (org.junit.Test)6 Job (org.opencastproject.job.api.Job)5 JobBarrier (org.opencastproject.job.api.JobBarrier)4 URI (java.net.URI)3 SearchResultItem (org.opencastproject.search.api.SearchResultItem)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)3 ArrayList (java.util.ArrayList)2 SearchException (org.opencastproject.search.api.SearchException)2 User (org.opencastproject.security.api.User)2 NotFoundException (org.opencastproject.util.NotFoundException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 HttpResponse (org.apache.http.HttpResponse)1 NameValuePair (org.apache.http.NameValuePair)1