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