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);
}
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;
}
}
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);
}
}
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());
}
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();
}
Aggregations