Search in sources :

Example 51 with MediaPackage

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!");
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 52 with MediaPackage

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();
    }
}
Also used : FileUploadJob(org.opencastproject.fileupload.api.job.FileUploadJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) FileUploadException(org.opencastproject.fileupload.api.exception.FileUploadException) FileUploadException(org.opencastproject.fileupload.api.exception.FileUploadException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 53 with MediaPackage

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());
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Event(org.opencastproject.index.service.impl.index.event.Event) EventIndexUtils.getOrCreateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.getOrCreateEvent) EventIndexUtils.updateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.updateEvent) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 54 with MediaPackage

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);
}
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 55 with MediaPackage

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());
}
Also used : Status(org.opencastproject.job.api.Job.Status) SearchQuery(org.opencastproject.search.api.SearchQuery) JobImpl(org.opencastproject.job.api.JobImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) MediaPackage(org.opencastproject.mediapackage.MediaPackage) List(java.util.List) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Test(org.junit.Test)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43