Search in sources :

Example 96 with MediaPackageElementFlavor

use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.

the class ZipWorkflowOperationHandler method zip.

/**
 * Creates a zip archive of all elements in a mediapackage.
 *
 * @param mediaPackage
 *          the mediapackage to zip
 *
 * @return the zip file
 *
 * @throws IOException
 *           If an IO exception occurs
 * @throws NotFoundException
 *           If a file referenced in the mediapackage can not be found
 * @throws MediaPackageException
 *           If the mediapackage can not be serialized to xml
 * @throws WorkflowOperationException
 *           If the mediapackage is invalid
 */
protected File zip(MediaPackage mediaPackage, List<MediaPackageElementFlavor> flavorsToZip, boolean compress) throws IOException, NotFoundException, MediaPackageException, WorkflowOperationException {
    if (mediaPackage == null) {
        throw new WorkflowOperationException("Invalid mediapackage");
    }
    // Create the temp directory
    File mediaPackageDir = new File(tempStorageDir, mediaPackage.getIdentifier().compact());
    FileUtils.forceMkdir(mediaPackageDir);
    // Link or copy each matching element's file from the workspace to the temp directory
    MediaPackageSerializer serializer = new DefaultMediaPackageSerializerImpl(mediaPackageDir);
    MediaPackage clone = (MediaPackage) mediaPackage.clone();
    for (MediaPackageElement element : clone.getElements()) {
        // remove the element if it doesn't match the flavors to zip
        boolean remove = true;
        for (MediaPackageElementFlavor flavor : flavorsToZip) {
            if (flavor.matches(element.getFlavor())) {
                remove = false;
                break;
            }
        }
        if (remove) {
            clone.remove(element);
            continue;
        }
        File elementDir = new File(mediaPackageDir, element.getIdentifier());
        FileUtils.forceMkdir(elementDir);
        File workspaceFile = workspace.get(element.getURI());
        File linkedFile = FileSupport.link(workspaceFile, new File(elementDir, workspaceFile.getName()), true);
        try {
            element.setURI(serializer.encodeURI(linkedFile.toURI()));
        } catch (URISyntaxException e) {
            throw new MediaPackageException("unable to serialize a mediapackage element", e);
        }
    }
    // Add the manifest
    FileUtils.writeStringToFile(new File(mediaPackageDir, "manifest.xml"), MediaPackageParser.getAsXml(clone), "UTF-8");
    // Zip the directory
    File zip = new File(tempStorageDir, clone.getIdentifier().compact() + ".zip");
    int compressValue = compress ? ZipUtil.DEFAULT_COMPRESSION : ZipUtil.NO_COMPRESSION;
    long startTime = System.currentTimeMillis();
    ZipUtil.zip(new File[] { mediaPackageDir }, zip, true, compressValue);
    long stopTime = System.currentTimeMillis();
    logger.debug("Zip file creation took {} seconds", (stopTime - startTime) / 1000);
    // Remove the directory
    FileUtils.forceDelete(mediaPackageDir);
    // Return the zip
    return zip;
}
Also used : DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) MediaPackageSerializer(org.opencastproject.mediapackage.MediaPackageSerializer) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) URISyntaxException(java.net.URISyntaxException) File(java.io.File) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 97 with MediaPackageElementFlavor

use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.

the class VideoEditorServiceImpl method processSmil.

/**
 * Splice segments given by smil document for the given track to the new one.
 *
 * @param job
 *          processing job
 * @param smil
 *          smil document with media segments description
 * @param trackParamGroupId
 * @return processed track
 * @throws ProcessFailedException
 *           if an error occured
 */
protected Track processSmil(Job job, Smil smil, String trackParamGroupId) throws ProcessFailedException {
    SmilMediaParamGroup trackParamGroup;
    ArrayList<String> inputfile = new ArrayList<>();
    ArrayList<VideoClip> videoclips = new ArrayList<>();
    try {
        trackParamGroup = (SmilMediaParamGroup) smil.get(trackParamGroupId);
    } catch (SmilException ex) {
        // can't be thrown, because we found the Id in processSmil(Smil)
        throw new ProcessFailedException("Smil does not contain a paramGroup element with Id " + trackParamGroupId);
    }
    MediaPackageElementFlavor sourceTrackFlavor = null;
    String sourceTrackUri = null;
    // get source track metadata
    for (SmilMediaParam param : trackParamGroup.getParams()) {
        if (SmilMediaParam.PARAM_NAME_TRACK_SRC.equals(param.getName())) {
            sourceTrackUri = param.getValue();
        } else if (SmilMediaParam.PARAM_NAME_TRACK_FLAVOR.equals(param.getName())) {
            sourceTrackFlavor = MediaPackageElementFlavor.parseFlavor(param.getValue());
        }
    }
    File sourceFile;
    try {
        sourceFile = workspace.get(new URI(sourceTrackUri));
    } catch (IOException ex) {
        throw new ProcessFailedException("Can't read " + sourceTrackUri);
    } catch (NotFoundException ex) {
        throw new ProcessFailedException("Workspace does not contain a track " + sourceTrackUri);
    } catch (URISyntaxException ex) {
        throw new ProcessFailedException("Source URI " + sourceTrackUri + " is not valid.");
    }
    // inspect input file to retrieve media information
    Job inspectionJob;
    Track sourceTrack;
    try {
        inspectionJob = inspect(job, new URI(sourceTrackUri));
        sourceTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
    } catch (URISyntaxException e) {
        throw new ProcessFailedException("Source URI " + sourceTrackUri + " is not valid.");
    } catch (MediaInspectionException e) {
        throw new ProcessFailedException("Media inspection of " + sourceTrackUri + " failed", e);
    } catch (MediaPackageException e) {
        throw new ProcessFailedException("Deserialization of source track " + sourceTrackUri + " failed", e);
    }
    // get output file extension
    String outputFileExtension = properties.getProperty(VideoEditorProperties.DEFAULT_EXTENSION, ".mp4");
    outputFileExtension = properties.getProperty(VideoEditorProperties.OUTPUT_FILE_EXTENSION, outputFileExtension);
    if (!outputFileExtension.startsWith(".")) {
        outputFileExtension = '.' + outputFileExtension;
    }
    // create working directory
    File tempDirectory = new File(new File(workspace.rootDirectory()), "editor");
    tempDirectory = new File(tempDirectory, Long.toString(job.getId()));
    String filename = String.format("%s-%s%s", sourceTrackFlavor, sourceFile.getName(), outputFileExtension);
    File outputPath = new File(tempDirectory, filename);
    if (!outputPath.getParentFile().exists()) {
        outputPath.getParentFile().mkdirs();
    }
    URI newTrackURI;
    // default source - add to source table as 0
    inputfile.add(sourceFile.getAbsolutePath());
    // index = 0
    int srcIndex = inputfile.indexOf(sourceFile.getAbsolutePath());
    logger.info("Start processing srcfile {}", sourceFile.getAbsolutePath());
    try {
        // parse body elements
        for (SmilMediaObject element : smil.getBody().getMediaElements()) {
            // body should contain par elements
            if (element.isContainer()) {
                SmilMediaContainer container = (SmilMediaContainer) element;
                if (SmilMediaContainer.ContainerType.PAR == container.getContainerType()) {
                    // par element should contain media elements
                    for (SmilMediaObject elementChild : container.getElements()) {
                        if (!elementChild.isContainer()) {
                            SmilMediaElement media = (SmilMediaElement) elementChild;
                            if (trackParamGroupId.equals(media.getParamGroup())) {
                                long begin = media.getClipBeginMS();
                                long end = media.getClipEndMS();
                                URI clipTrackURI = media.getSrc();
                                File clipSourceFile = null;
                                if (clipTrackURI != null) {
                                    try {
                                        clipSourceFile = workspace.get(clipTrackURI);
                                    } catch (IOException ex) {
                                        throw new ProcessFailedException("Can't read " + clipTrackURI);
                                    } catch (NotFoundException ex) {
                                        throw new ProcessFailedException("Workspace does not contain a track " + clipTrackURI);
                                    }
                                }
                                int index;
                                if (clipSourceFile != null) {
                                    // clip has different source
                                    // Look for known tracks
                                    index = inputfile.indexOf(clipSourceFile.getAbsolutePath());
                                    if (index == -1) {
                                        // add new track
                                        inputfile.add(clipSourceFile.getAbsolutePath());
                                    // TODO: inspect each new video file, bad input will throw exc
                                    }
                                    index = inputfile.indexOf(clipSourceFile.getAbsolutePath());
                                } else {
                                    // default src
                                    index = srcIndex;
                                }
                                videoclips.add(new VideoClip(index, begin / 1000.0, end / 1000.0));
                            }
                        } else {
                            throw new ProcessFailedException("Smil container '" + ((SmilMediaContainer) elementChild).getContainerType().toString() + "'is not supportet yet");
                        }
                    }
                } else {
                    throw new ProcessFailedException("Smil container '" + container.getContainerType().toString() + "'is not supportet yet");
                }
            }
        }
        // remove very short cuts that will look bad
        List<VideoClip> cleanclips = sortSegments(videoclips);
        String error = null;
        // TODO: fetch the largest output resolution from SMIL.head.layout.root-layout
        String outputResolution = "";
        // When outputResolution is set to WxH, all clips are scaled to that size in the output video.
        // TODO: Each clips could have a region id, relative to the root-layout
        // Then each clip is zoomed/panned/padded to WxH befor concatenation
        FFmpegEdit ffmpeg = new FFmpegEdit(properties);
        error = ffmpeg.processEdits(inputfile, outputPath.getAbsolutePath(), outputResolution, cleanclips, sourceTrack.hasAudio(), sourceTrack.hasVideo());
        if (error != null) {
            FileUtils.deleteQuietly(tempDirectory);
            throw new ProcessFailedException("Editing pipeline exited abnormaly! Error: " + error);
        }
        // create Track for edited file
        String newTrackId = idBuilder.createNew().toString();
        InputStream in = new FileInputStream(outputPath);
        try {
            newTrackURI = workspace.putInCollection(COLLECTION_ID, String.format("%s-%s%s", sourceTrackFlavor.getType(), newTrackId, outputFileExtension), in);
        } catch (IllegalArgumentException ex) {
            throw new ProcessFailedException("Copy track into workspace failed! " + ex.getMessage());
        } finally {
            IOUtils.closeQuietly(in);
            FileUtils.deleteQuietly(tempDirectory);
        }
        // inspect new Track
        try {
            inspectionJob = inspect(job, newTrackURI);
        } catch (MediaInspectionException e) {
            throw new ProcessFailedException("Media inspection of " + newTrackURI + " failed", e);
        }
        Track editedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
        logger.info("Finished editing track {}", editedTrack);
        editedTrack.setIdentifier(newTrackId);
        editedTrack.setFlavor(new MediaPackageElementFlavor(sourceTrackFlavor.getType(), SINK_FLAVOR_SUBTYPE));
        return editedTrack;
    } catch (MediaInspectionException ex) {
        throw new ProcessFailedException("Inspecting encoded Track failed with: " + ex.getMessage());
    } catch (MediaPackageException ex) {
        throw new ProcessFailedException("Unable to serialize edited Track! " + ex.getMessage());
    } catch (Exception ex) {
        throw new ProcessFailedException("Unable to process SMIL: " + ex.getMessage(), ex);
    } finally {
        FileUtils.deleteQuietly(tempDirectory);
    }
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) SmilException(org.opencastproject.smil.api.SmilException) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) SmilMediaParamGroup(org.opencastproject.smil.entity.media.param.api.SmilMediaParamGroup) Job(org.opencastproject.job.api.Job) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) FFmpegEdit(org.opencastproject.videoeditor.ffmpeg.FFmpegEdit) SmilMediaParam(org.opencastproject.smil.entity.media.param.api.SmilMediaParam) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) SmilException(org.opencastproject.smil.api.SmilException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JAXBException(javax.xml.bind.JAXBException) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Track(org.opencastproject.mediapackage.Track)

Example 98 with MediaPackageElementFlavor

use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.

the class SilenceDetectionWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mp = workflowInstance.getMediaPackage();
    logger.debug("Start silence detection workflow operation for mediapackage {}", mp.getIdentifier().compact());
    String sourceFlavors = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SOURCE_FLAVORS_PROPERTY));
    String sourceFlavor = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SOURCE_FLAVOR_PROPERTY));
    String smilFlavorSubType = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SMIL_FLAVOR_SUBTYPE_PROPERTY));
    String smilTargetFlavorString = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SMIL_TARGET_FLAVOR_PROPERTY));
    MediaPackageElementFlavor smilTargetFlavor = null;
    if (smilTargetFlavorString != null)
        smilTargetFlavor = MediaPackageElementFlavor.parseFlavor(smilTargetFlavorString);
    if (sourceFlavor == null && sourceFlavors == null) {
        throw new WorkflowOperationException(String.format("No %s or %s have been specified", SOURCE_FLAVOR_PROPERTY, SOURCE_FLAVORS_PROPERTY));
    }
    if (smilFlavorSubType == null && smilTargetFlavor == null) {
        throw new WorkflowOperationException(String.format("No %s or %s have been specified", SMIL_FLAVOR_SUBTYPE_PROPERTY, SMIL_TARGET_FLAVOR_PROPERTY));
    }
    if (sourceFlavors != null && smilTargetFlavor != null) {
        throw new WorkflowOperationException(String.format("Can't use %s and %s together", SOURCE_FLAVORS_PROPERTY, SMIL_TARGET_FLAVOR_PROPERTY));
    }
    final String finalSourceFlavors;
    if (smilTargetFlavor != null) {
        finalSourceFlavors = sourceFlavor;
    } else {
        finalSourceFlavors = sourceFlavors;
    }
    String referenceTracksFlavor = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(REFERENCE_TRACKS_FLAVOR_PROPERTY));
    if (referenceTracksFlavor == null)
        referenceTracksFlavor = finalSourceFlavors;
    TrackSelector trackSelector = new TrackSelector();
    for (String flavor : asList(finalSourceFlavors)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> sourceTracks = trackSelector.select(mp, false);
    if (sourceTracks.isEmpty()) {
        logger.info("No source tracks found, skip silence detection");
        return createResult(mp, Action.SKIP);
    }
    trackSelector = new TrackSelector();
    for (String flavor : asList(referenceTracksFlavor)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> referenceTracks = trackSelector.select(mp, false);
    if (referenceTracks.isEmpty()) {
        // REFERENCE_TRACKS_FLAVOR_PROPERTY was set to wrong value
        throw new WorkflowOperationException(String.format("No tracks found filtered by flavor(s) '%s'", referenceTracksFlavor));
    }
    MediaPackageElementBuilder mpeBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    for (Track sourceTrack : sourceTracks) {
        // Skip over track with no audio stream
        if (!sourceTrack.hasAudio()) {
            logger.info("Skipping silence detection of track {} since it has no audio", sourceTrack);
            continue;
        }
        logger.info("Executing silence detection on track {}", sourceTrack.getIdentifier());
        try {
            Job detectionJob = detetionService.detect(sourceTrack, referenceTracks.toArray(new Track[referenceTracks.size()]));
            if (!waitForStatus(detectionJob).isSuccess()) {
                throw new WorkflowOperationException("Silence Detection failed");
            }
            Smil smil = smilService.fromXml(detectionJob.getPayload()).getSmil();
            InputStream is = null;
            try {
                is = IOUtils.toInputStream(smil.toXML(), "UTF-8");
                URI smilURI = workspace.put(mp.getIdentifier().compact(), smil.getId(), TARGET_FILE_NAME, is);
                MediaPackageElementFlavor smilFlavor = smilTargetFlavor;
                if (smilFlavor == null)
                    smilFlavor = new MediaPackageElementFlavor(sourceTrack.getFlavor().getType(), smilFlavorSubType);
                Catalog catalog = (Catalog) mpeBuilder.elementFromURI(smilURI, MediaPackageElement.Type.Catalog, smilFlavor);
                catalog.setIdentifier(smil.getId());
                mp.add(catalog);
            } catch (Exception ex) {
                throw new WorkflowOperationException(String.format("Failed to put smil into workspace. Silence detection for track %s failed", sourceTrack.getIdentifier()), ex);
            } finally {
                IOUtils.closeQuietly(is);
            }
            logger.info("Finished silence detection on track {}", sourceTrack.getIdentifier());
        } catch (SilenceDetectionFailedException ex) {
            throw new WorkflowOperationException(String.format("Failed to create silence detection job for track %s", sourceTrack.getIdentifier()));
        } catch (SmilException ex) {
            throw new WorkflowOperationException(String.format("Failed to get smil from silence detection job for track %s", sourceTrack.getIdentifier()));
        }
    }
    logger.debug("Finished silence detection workflow operation for mediapackage {}", mp.getIdentifier().compact());
    return createResult(mp, Action.CONTINUE);
}
Also used : SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) InputStream(java.io.InputStream) TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) SmilException(org.opencastproject.smil.api.SmilException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Smil(org.opencastproject.smil.entity.api.Smil) SmilException(org.opencastproject.smil.api.SmilException) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track)

Example 99 with MediaPackageElementFlavor

use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.

the class EmailSchedulerConflictNotifierTest method testEmailSchedulerConflict.

@Test
public void testEmailSchedulerConflict() throws Exception {
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    Map<String, String> caProperties = new HashMap<String, String>();
    caProperties.put("test", "true");
    caProperties.put("clear", "all");
    Map<String, String> wfProperties = new HashMap<String, String>();
    wfProperties.put("test", "false");
    wfProperties.put("skip", "true");
    final String mpId = "1234";
    final TechnicalMetadata technicalMetadata = new TechnicalMetadataImpl(mpId, "demo", new Date(), new Date(new Date().getTime() + 10 * 60 * 1000), false, userIds, wfProperties, caProperties, null);
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.setIdentifier(new IdImpl(mpId));
    mp.add(DublinCores.mkOpencastEpisode().getCatalog());
    DublinCoreCatalog extendedEvent = DublinCores.mkStandard();
    extendedEvent.setFlavor(new MediaPackageElementFlavor("extended", "episode"));
    mp.add(extendedEvent);
    final SchedulerEvent schedulerEvent = EasyMock.createNiceMock(SchedulerEvent.class);
    EasyMock.expect(schedulerEvent.getTechnicalMetadata()).andReturn(technicalMetadata).anyTimes();
    EasyMock.expect(schedulerEvent.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(schedulerEvent.getEventId()).andReturn(mpId).anyTimes();
    EasyMock.expect(schedulerEvent.getVersion()).andReturn("2").anyTimes();
    EasyMock.replay(schedulerEvent);
    ConflictingEvent conflictingEvent = EasyMock.createNiceMock(ConflictingEvent.class);
    EasyMock.expect(conflictingEvent.getOldEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getNewEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getConflictStrategy()).andReturn(Strategy.NEW).anyTimes();
    EasyMock.replay(conflictingEvent);
    List<ConflictingEvent> conflicts = new ArrayList<>();
    conflicts.add(conflictingEvent);
    final Integer[] counter = new Integer[1];
    counter[0] = 0;
    SmtpService smtpService = new SmtpService() {

        @Override
        public void send(MimeMessage message) throws MessagingException {
            counter[0]++;
        }
    };
    conflictNotifier.setSmtpService(smtpService);
    conflictNotifier.notifyConflicts(conflicts);
    Assert.assertEquals(1, counter[0].intValue());
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) SmtpService(org.opencastproject.kernel.mail.SmtpService) MimeMessage(javax.mail.internet.MimeMessage) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 100 with MediaPackageElementFlavor

use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.

the class SchedulerServiceImplTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    wfProperties.put("test", "true");
    wfProperties.put("clear", "all");
    wfPropertiesUpdated.put("test", "false");
    wfPropertiesUpdated.put("skip", "true");
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    schedulerDatabase = new SchedulerServiceDatabaseImpl();
    schedulerDatabase.setEntityManagerFactory(mkEntityManagerFactory(SchedulerServiceDatabaseImpl.PERSISTENCE_UNIT));
    schedulerDatabase.setSecurityService(securityService);
    schedulerDatabase.activate(null);
    workspace = new UnitTestWorkspace();
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    final BaseMessage baseMessageMock = EasyMock.createNiceMock(BaseMessage.class);
    MessageReceiver messageReceiver = EasyMock.createNiceMock(MessageReceiver.class);
    EasyMock.expect(messageReceiver.receiveSerializable(EasyMock.anyString(), EasyMock.anyObject(MessageSender.DestinationType.class))).andStubReturn(new FutureTask<>(new Callable<Serializable>() {

        @Override
        public Serializable call() throws Exception {
            return baseMessageMock;
        }
    }));
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    acl = new AccessControlList(new AccessControlEntry("ROLE_ADMIN", "write", true), new AccessControlEntry("ROLE_ADMIN", "read", true), new AccessControlEntry("ROLE_USER", "read", true));
    EasyMock.expect(authorizationService.getAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class))).andReturn(Option.some(acl)).anyTimes();
    OrganizationDirectoryService orgDirectoryService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectoryService.getOrganizations()).andReturn(Arrays.asList((Organization) new DefaultOrganization())).anyTimes();
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getProperty(EasyMock.anyString())).andReturn("adminuser").anyTimes();
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.replay(messageSender, baseMessageMock, messageReceiver, authorizationService, securityService, extendedAdapter, episodeAdapter, orgDirectoryService, componentContext, bundleContext);
    testConflictHandler = new TestConflictHandler();
    schedSvc = new SchedulerServiceImpl();
    schedSvc.setAuthorizationService(authorizationService);
    schedSvc.setSecurityService(securityService);
    schedSvc.setPersistence(schedulerDatabase);
    schedSvc.setWorkspace(workspace);
    schedSvc.setMessageSender(messageSender);
    schedSvc.setMessageReceiver(messageReceiver);
    schedSvc.setConflictHandler(testConflictHandler);
    schedSvc.addCatalogUIAdapter(episodeAdapter);
    schedSvc.addCatalogUIAdapter(extendedAdapter);
    schedSvc.setOrgDirectoryService(orgDirectoryService);
    schedSvc.activate(componentContext);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ComponentContext(org.osgi.service.component.ComponentContext) MessageSender(org.opencastproject.message.broker.api.MessageSender) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Callable(java.util.concurrent.Callable) JaxbRole(org.opencastproject.security.api.JaxbRole) SchedulerServiceDatabaseImpl(org.opencastproject.scheduler.impl.persistence.SchedulerServiceDatabaseImpl) BaseMessage(org.opencastproject.message.broker.api.BaseMessage) MessageReceiver(org.opencastproject.message.broker.api.MessageReceiver) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) BundleContext(org.osgi.framework.BundleContext) BeforeClass(org.junit.BeforeClass)

Aggregations

MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)109 MediaPackage (org.opencastproject.mediapackage.MediaPackage)49 Track (org.opencastproject.mediapackage.Track)34 URI (java.net.URI)31 Test (org.junit.Test)31 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)28 IOException (java.io.IOException)27 NotFoundException (org.opencastproject.util.NotFoundException)27 ArrayList (java.util.ArrayList)26 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)26 HashMap (java.util.HashMap)23 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)22 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)22 Job (org.opencastproject.job.api.Job)21 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 InputStream (java.io.InputStream)18 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)17 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)16 File (java.io.File)13 Catalog (org.opencastproject.mediapackage.Catalog)13