use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IndexServiceImpl method getEventMediapackage.
@Override
public MediaPackage getEventMediapackage(Event event) throws IndexServiceException {
switch(getEventSource(event)) {
case WORKFLOW:
Opt<WorkflowInstance> currentWorkflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
if (currentWorkflowInstance.isNone()) {
logger.error("No workflow instance for event {} found!", event.getIdentifier());
throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
}
return currentWorkflowInstance.get().getMediaPackage();
case ARCHIVE:
final AQueryBuilder q = assetManager.createQuery();
final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(event.getIdentifier()).and(q.version().isLatest())).run();
if (r.getSize() > 0) {
logger.debug("Found event in archive with id {}", event.getIdentifier());
return enrich(r).getSnapshots().head2().getMediaPackage();
}
logger.error("No event with id {} found from archive!", event.getIdentifier());
throw new IndexServiceException("No archived event found with id " + event.getIdentifier());
case SCHEDULE:
try {
MediaPackage mediaPackage = schedulerService.getMediaPackage(event.getIdentifier());
logger.debug("Found event in scheduler with id {}", event.getIdentifier());
return mediaPackage;
} catch (NotFoundException e) {
logger.error("No scheduled event with id {} found!", event.getIdentifier());
throw new IndexServiceException(e.getMessage(), e);
} catch (UnauthorizedException e) {
logger.error("Unauthorized to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
throw new IndexServiceException(e.getMessage(), e);
} catch (SchedulerException e) {
logger.error("Unable to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
throw new IndexServiceException(e.getMessage(), e);
}
default:
throw new IllegalStateException("Unknown event type!");
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class FileUploadRestService method getNewJob.
// </editor-fold>
@POST
@Produces(MediaType.TEXT_PLAIN)
@Path("newjob")
@RestQuery(name = "newjob", description = "Creates a new upload job and returns the jobs ID.", restParameters = { @RestParameter(description = "The name of the file that will be uploaded", isRequired = false, name = REQUESTFIELD_FILENAME, type = RestParameter.Type.STRING), @RestParameter(description = "The size of the file that will be uploaded", isRequired = false, name = REQUESTFIELD_FILESIZE, type = RestParameter.Type.STRING), @RestParameter(description = "The size of the chunks that will be uploaded", isRequired = false, name = REQUESTFIELD_CHUNKSIZE, type = RestParameter.Type.STRING), @RestParameter(description = "The flavor of this track", isRequired = false, name = REQUESTFIELD_FLAVOR, type = RestParameter.Type.STRING), @RestParameter(description = "The mediapackage the file should belong to", isRequired = false, name = REQUESTFIELD_MEDIAPACKAGE, type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "job was successfully created", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "upload service gave an error", responseCode = HttpServletResponse.SC_NO_CONTENT) }, returnDescription = "The ID of the newly created upload job")
public Response getNewJob(@FormParam(REQUESTFIELD_FILENAME) String filename, @FormParam(REQUESTFIELD_FILESIZE) long filesize, @FormParam(REQUESTFIELD_CHUNKSIZE) int chunksize, @FormParam(REQUESTFIELD_MEDIAPACKAGE) String mediapackage, @FormParam(REQUESTFIELD_FLAVOR) String flav) {
try {
if (StringUtils.isBlank(filename)) {
filename = "john.doe";
}
if (filesize < 1) {
filesize = -1;
}
if (chunksize < 1) {
chunksize = -1;
}
MediaPackage mp = null;
if (StringUtils.isNotBlank(mediapackage)) {
mp = factory.newMediaPackageBuilder().loadFromXml(mediapackage);
}
MediaPackageElementFlavor flavor = null;
if (StringUtils.isNotBlank(flav)) {
flavor = new MediaPackageElementFlavor(flav.split("/")[0], flav.split("/")[1]);
}
FileUploadJob job = uploadService.createJob(filename, filesize, chunksize, mp, flavor);
return Response.ok(job.getId()).build();
} catch (FileUploadException e) {
log.error(e.getMessage(), e);
return Response.status(Response.Status.NO_CONTENT).entity(e.getMessage()).build();
} catch (Exception e) {
log.error(e.getMessage(), e);
return Response.serverError().entity(buildUnexpectedErrorMessage(e)).build();
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AssetManagerMessageReceiverImpl method handleMessage.
/**
* Handle an update message.
*/
private void handleMessage(TakeSnapshot msg) {
logger.debug("Received AssetManager take snapshot message");
final MediaPackage mp = msg.getMediapackage();
final Opt<DublinCoreCatalog> episodeDublincore = msg.getEpisodeDublincore();
final String organization = getSecurityService().getOrganization().getId();
final User user = getSecurityService().getUser();
// Load or create the corresponding recording event
final Event event;
try {
event = getOrCreateEvent(mp.getIdentifier().toString(), organization, user, getSearchIndex());
final AccessControlList acl = msg.getAcl();
List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
for (final ManagedAcl managedAcl : AccessInformationUtil.matchAcls(acls, acl)) {
event.setManagedAcl(managedAcl.getName());
}
event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
event.setArchiveVersion(msg.getVersion());
if (isBlank(event.getCreator()))
event.setCreator(getSecurityService().getUser().getName());
updateEvent(event, mp);
if (episodeDublincore.isSome()) {
updateEvent(event, episodeDublincore.get());
}
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
return;
}
// Update series name if not already done
try {
EventIndexUtils.updateSeriesName(event, organization, user, getSearchIndex());
} catch (SearchIndexException e) {
logger.error("Error updating the series name of the event to index: {}", ExceptionUtils.getStackTrace(e));
}
// Persist the scheduling event
try {
getSearchIndex().addOrUpdate(event);
logger.debug("Asset manager entry {} updated in the admin ui search index", event.getIdentifier());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
}
}
use of org.opencastproject.mediapackage.MediaPackage 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.mediapackage.MediaPackage in project opencast by opencast.
the class SearchServiceImplTest method testPopulateIndex.
@SuppressWarnings("unchecked")
@Test
public void testPopulateIndex() throws Exception {
// This service registry must return a list of jobs
List<String> args = new ArrayList<String>();
args.add(new DefaultOrganization().getId());
List<Job> jobs = new ArrayList<Job>();
for (long i = 0; i < 10; i++) {
MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mediaPackage.setIdentifier(IdBuilderFactory.newInstance().newIdBuilder().createNew());
searchDatabase.storeMediaPackage(mediaPackage, acl, new Date());
String payload = MediaPackageParser.getAsXml(mediaPackage);
Job job = new JobImpl(i);
job.setArguments(args);
job.setPayload(payload);
job.setStatus(Status.FINISHED);
jobs.add(job);
}
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.createJob((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (List<String>) EasyMock.anyObject(), (String) EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(new JobImpl()).anyTimes();
EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(new JobImpl()).anyTimes();
EasyMock.expect(serviceRegistry.getJobs((String) EasyMock.anyObject(), (Status) EasyMock.anyObject())).andReturn(jobs).anyTimes();
EasyMock.replay(serviceRegistry);
service.setServiceRegistry(serviceRegistry);
OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(orgDirectory);
service.setOrganizationDirectoryService(orgDirectory);
// We should have nothing in the search index
assertEquals(0, service.getByQuery(new SearchQuery()).size());
service.populateIndex("System Admin");
// This time we should have 10 results
assertEquals(10, service.getByQuery(new SearchQuery()).size());
}
Aggregations