Search in sources :

Example 21 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class EmailDataTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    uriMP = EmailDataTest.class.getResource("/email_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    URI episodeURI = EmailDataTest.class.getResource("/episode_dublincore.xml").toURI();
    URI seriesURI = EmailDataTest.class.getResource("/series_dublincore.xml").toURI();
    DublinCoreCatalog episodeDc = DublinCores.read(episodeURI.toURL().openStream());
    catalogs.put("episode", buildCatalogHash(episodeDc));
    DublinCoreCatalog seriesDc = DublinCores.read(seriesURI.toURL().openStream());
    catalogs.put("series", buildCatalogHash(seriesDc));
    WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
    def.setId("wfdef");
    Map<String, String> props = new HashMap<String, String>();
    props.put("emailAddress", "user@domain.com");
    // Create some incidents
    incident1 = EasyMock.createNiceMock(Incident.class);
    List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
    Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
    details.add(detail);
    EasyMock.expect(incident1.getDetails()).andReturn(details);
    incident2 = EasyMock.createNiceMock(Incident.class);
    details = new LinkedList<Tuple<String, String>>();
    detail = new Tuple<String, String>("detail-type", "error in operation2");
    details.add(detail);
    EasyMock.expect(incident2.getDetails()).andReturn(details);
    // Link the incident and the subtree
    incidents = new LinkedList<Incident>();
    incidents.add(incident1);
    incidents.add(incident2);
    workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    failedOperation = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
    List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
    operationList.add(failedOperation);
    operationList.add(operation);
    workflowInstance.setOperations(operationList);
    EasyMock.replay(incident1, incident2);
}
Also used : WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) URI(java.net.URI) LinkedList(java.util.LinkedList) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Incident(org.opencastproject.job.api.Incident) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Tuple(org.opencastproject.util.data.Tuple) Before(org.junit.Before)

Example 22 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class EmailTemplateServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    uriMP = EmailTemplateServiceImplTest.class.getResource("/email_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    service = new EmailTemplateServiceImpl();
    URI episodeURI = EmailTemplateServiceImplTest.class.getResource("/episode_dublincore.xml").toURI();
    URI seriesURI = EmailTemplateServiceImplTest.class.getResource("/series_dublincore.xml").toURI();
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.get(new URI("episode_dublincore.xml"))).andReturn(new File(episodeURI));
    EasyMock.expect(workspace.get(new URI("series_dublincore.xml"))).andReturn(new File(seriesURI));
    EasyMock.replay(workspace);
    service.setWorkspace(workspace);
    EmailTemplateScanner templateScanner = EasyMock.createMock(EmailTemplateScanner.class);
    EasyMock.expect(templateScanner.getTemplate("templateBasic")).andReturn("Media package id: ${mediaPackage.identifier}, workflow id: ${workflow.id}, " + "title: ${mediaPackage.title}, series title: ${mediaPackage.seriesTitle}, " + "date: ${mediaPackage.date?datetime?iso_utc}");
    EasyMock.expect(templateScanner.getTemplate("templateCatalog")).andReturn("EPISODE creator: ${catalogs[\"episode\"][\"creator\"]}, isPartOf: ${catalogs[\"episode\"][\"isPartOf\"]}, " + "title: ${catalogs[\"episode\"][\"title\"]}, created: ${catalogs[\"episode\"][\"created\"]}, " + "SERIES creator: ${catalogs[\"series\"][\"creator\"]}, description: ${catalogs[\"series\"][\"description\"]}, " + "subject: ${catalogs[\"series\"][\"subject\"]}");
    EasyMock.expect(templateScanner.getTemplate("templateFailed")).andReturn("<#if failedOperation?has_content>Workflow failed in operation: ${failedOperation.template}</#if>, " + "Workflow errors: <#list incident as inc><#list inc.details as de>${de.b} </#list></#list>");
    EasyMock.expect(templateScanner.getTemplate("templateSyntaxError")).andReturn("${mediaPackage");
    EasyMock.replay(templateScanner);
    service.setEmailTemplateScanner(templateScanner);
    WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
    def.setId("wfdef");
    Map<String, String> props = new HashMap<String, String>();
    props.put("emailAddress", "user@domain.com");
    IncidentService is = EasyMock.createMock(IncidentService.class);
    /*
     * This is what we're building. EasyMock makes it ugly, of course /-------job1Tree / | / incident2 subtree |
     * incident1
     */
    // Create the tree and subtree
    IncidentTree subtree = EasyMock.createNiceMock(IncidentTree.class);
    IncidentTree job1Tree = EasyMock.createNiceMock(IncidentTree.class);
    // Create the incidents
    Incident incident1 = EasyMock.createNiceMock(Incident.class);
    List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
    Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
    details.add(detail);
    EasyMock.expect(incident1.getDetails()).andReturn(details);
    Incident incident2 = EasyMock.createNiceMock(Incident.class);
    details = new LinkedList<Tuple<String, String>>();
    detail = new Tuple<String, String>("detail-type", "error in operation2");
    details.add(detail);
    EasyMock.expect(incident2.getDetails()).andReturn(details);
    // Link the incident and the subtree
    LinkedList<Incident> incidents = new LinkedList<Incident>();
    incidents.add(incident1);
    EasyMock.expect(subtree.getIncidents()).andReturn(incidents).anyTimes();
    // This is what Entwine wrote in the IncidentTree class, so rather than null we're using Immutables.nil()
    List<IncidentTree> subtreeDecendants = Immutables.nil();
    EasyMock.expect(subtree.getDescendants()).andReturn(subtreeDecendants).anyTimes();
    // Link the incident and the parent tree
    incidents = new LinkedList<Incident>();
    incidents.add(incident2);
    EasyMock.expect(job1Tree.getIncidents()).andReturn(incidents).anyTimes();
    // Link the subtree and parent tree
    LinkedList<IncidentTree> subtreeList = new LinkedList<IncidentTree>();
    subtreeList.add(subtree);
    EasyMock.expect(job1Tree.getDescendants()).andReturn(subtreeList).anyTimes();
    service.setIncidentService(is);
    workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl failedOperation1 = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
    failedOperation1.setFailWorkflowOnException(true);
    failedOperation1.setId(1L);
    EasyMock.expect(is.getIncidentsOfJob(1L, true)).andReturn(subtree).anyTimes();
    WorkflowOperationInstanceImpl failedOperation2 = new WorkflowOperationInstanceImpl("operation2", OperationState.FAILED);
    failedOperation2.setFailWorkflowOnException(false);
    failedOperation1.setId(2L);
    EasyMock.expect(is.getIncidentsOfJob(2L, true)).andReturn(job1Tree).anyTimes();
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
    List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
    operationList.add(failedOperation1);
    operationList.add(failedOperation2);
    operationList.add(operation);
    workflowInstance.setOperations(operationList);
    EasyMock.replay(is, subtree, job1Tree, incident1, incident2);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) URI(java.net.URI) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) IncidentTree(org.opencastproject.job.api.IncidentTree) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) LinkedList(java.util.LinkedList) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) Incident(org.opencastproject.job.api.Incident) File(java.io.File) Tuple(org.opencastproject.util.data.Tuple) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 23 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class MetadataList method toJSON.

public JValue toJSON() {
    List<JValue> catalogs = new ArrayList<>();
    for (Entry<String, Tuple<String, MetadataCollection>> metadata : metadataList.entrySet()) {
        List<Field> fields = new ArrayList<>();
        MetadataCollection metadataCollection = metadata.getValue().getB();
        if (!Locked.NONE.equals(locked)) {
            fields.add(f(KEY_METADATA_LOCKED, v(locked.getValue())));
            makeMetadataCollectionReadOnly(metadataCollection);
        }
        fields.add(f(KEY_METADATA_FLAVOR, v(metadata.getKey())));
        fields.add(f(KEY_METADATA_TITLE, v(metadata.getValue().getA())));
        fields.add(f(KEY_METADATA_FIELDS, metadataCollection.toJSON()));
        catalogs.add(obj(fields));
    }
    return arr(catalogs);
}
Also used : MetadataField(org.opencastproject.metadata.dublincore.MetadataField) Field(com.entwinemedia.fn.data.json.Field) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Tuple(org.opencastproject.util.data.Tuple)

Example 24 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class CompositeWorkflowOperationHandler method handleSingleTrack.

private WorkflowOperationResult handleSingleTrack(MediaPackage mediaPackage, WorkflowOperationInstance operation, CompositeSettings compositeSettings, Option<Attachment> watermarkAttachment) throws EncoderException, IOException, NotFoundException, MediaPackageException, WorkflowOperationException {
    if (compositeSettings.getSingleSourceLayout() == null) {
        throw new WorkflowOperationException("Single video layout must be set! Please verify that you have a " + LAYOUT_SINGLE + " property in your composite operation in your workflow definition.");
    }
    try {
        VideoStream[] videoStreams = TrackSupport.byType(compositeSettings.getSingleTrack().getStreams(), VideoStream.class);
        if (videoStreams.length == 0) {
            logger.warn("No video stream available to compose! {}", compositeSettings.getSingleTrack());
            return createResult(mediaPackage, Action.SKIP);
        }
        // Read the video dimensions from the mediapackage stream information
        Dimension videoDimension = Dimension.dimension(videoStreams[0].getFrameWidth(), videoStreams[0].getFrameHeight());
        // Create the video layout definitions
        List<Tuple<Dimension, HorizontalCoverageLayoutSpec>> shapes = new ArrayList<Tuple<Dimension, HorizontalCoverageLayoutSpec>>();
        shapes.add(0, Tuple.tuple(videoDimension, compositeSettings.getSingleSourceLayout()));
        // Determine dimension of output
        Dimension outputDimension = null;
        String outputResolutionSource = compositeSettings.getOutputResolutionSource();
        if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_FIXED)) {
            outputDimension = compositeSettings.getOutputDimension();
        } else if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_LOWER)) {
            outputDimension = videoDimension;
        } else if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_UPPER)) {
            outputDimension = videoDimension;
        }
        // Calculate the single layout
        MultiShapeLayout multiShapeLayout = LayoutManager.multiShapeLayout(outputDimension, shapes);
        // Create the laid out element for the videos
        LaidOutElement<Track> lowerLaidOutElement = new LaidOutElement<Track>(compositeSettings.getSingleTrack(), multiShapeLayout.getShapes().get(0));
        // Create the optionally laid out element for the watermark
        Option<LaidOutElement<Attachment>> watermarkOption = createWatermarkLaidOutElement(compositeSettings, outputDimension, watermarkAttachment);
        Job compositeJob = composerService.composite(outputDimension, Option.<LaidOutElement<Track>>none(), lowerLaidOutElement, watermarkOption, compositeSettings.getProfile().getIdentifier(), compositeSettings.getOutputBackground());
        // Wait for the jobs to return
        if (!waitForStatus(compositeJob).isSuccess())
            throw new WorkflowOperationException("The composite job did not complete successfully");
        if (compositeJob.getPayload().length() > 0) {
            Track compoundTrack = (Track) MediaPackageElementParser.getFromXml(compositeJob.getPayload());
            compoundTrack.setURI(workspace.moveTo(compoundTrack.getURI(), mediaPackage.getIdentifier().toString(), compoundTrack.getIdentifier(), "composite." + FilenameUtils.getExtension(compoundTrack.getURI().toString())));
            // Adjust the target tags
            for (String tag : compositeSettings.getTargetTags()) {
                logger.trace("Tagging compound track with '{}'", tag);
                compoundTrack.addTag(tag);
            }
            // Adjust the target flavor.
            compoundTrack.setFlavor(compositeSettings.getTargetFlavor());
            logger.debug("Compound track has flavor '{}'", compoundTrack.getFlavor());
            // store new tracks to mediaPackage
            mediaPackage.add(compoundTrack);
            WorkflowOperationResult result = createResult(mediaPackage, Action.CONTINUE, compositeJob.getQueueTime());
            logger.debug("Composite operation completed");
            return result;
        } else {
            logger.info("Composite operation unsuccessful, no payload returned: {}", compositeJob);
            return createResult(mediaPackage, Action.SKIP);
        }
    } finally {
        if (compositeSettings.getSourceUrlWatermark() != null)
            workspace.deleteFromCollection(COLLECTION, compositeSettings.getWatermarkIdentifier() + "." + FilenameUtils.getExtension(compositeSettings.getSourceUrlWatermark()));
    }
}
Also used : MultiShapeLayout(org.opencastproject.composer.layout.MultiShapeLayout) VideoStream(org.opencastproject.mediapackage.VideoStream) ArrayList(java.util.ArrayList) Dimension(org.opencastproject.composer.layout.Dimension) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) HorizontalCoverageLayoutSpec(org.opencastproject.composer.layout.HorizontalCoverageLayoutSpec) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple) Track(org.opencastproject.mediapackage.Track)

Example 25 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class SearchServiceImpl method populateIndex.

protected void populateIndex(String systemUserName) {
    long instancesInSolr = 0L;
    try {
        instancesInSolr = indexManager.count();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    if (instancesInSolr > 0) {
        logger.debug("Search index found");
        return;
    }
    if (instancesInSolr == 0L) {
        logger.info("No search index found");
        logger.info("Starting population of search index from database");
        Iterator<Tuple<MediaPackage, String>> mediaPackages;
        try {
            mediaPackages = persistence.getAllMediaPackages();
        } catch (SearchServiceDatabaseException e) {
            logger.error("Unable to load the search entries: {}", e.getMessage());
            throw new ServiceException(e.getMessage());
        }
        int errors = 0;
        while (mediaPackages.hasNext()) {
            try {
                Tuple<MediaPackage, String> mediaPackage = mediaPackages.next();
                String mediaPackageId = mediaPackage.getA().getIdentifier().toString();
                Organization organization = organizationDirectory.getOrganization(mediaPackage.getB());
                securityService.setOrganization(organization);
                securityService.setUser(SecurityUtil.createSystemUser(systemUserName, organization));
                AccessControlList acl = persistence.getAccessControlList(mediaPackageId);
                Date modificationDate = persistence.getModificationDate(mediaPackageId);
                Date deletionDate = persistence.getDeletionDate(mediaPackageId);
                indexManager.add(mediaPackage.getA(), acl, deletionDate, modificationDate);
            } catch (Exception e) {
                logger.error("Unable to index search instances:", e);
                if (retryToPopulateIndex(systemUserName)) {
                    logger.warn("Trying to re-index search index later. Aborting for now.");
                    return;
                }
                errors++;
            } finally {
                securityService.setOrganization(null);
                securityService.setUser(null);
            }
        }
        if (errors > 0)
            logger.error("Skipped {} erroneous search entries while populating the search index", errors);
        logger.info("Finished populating search index");
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) ServiceException(org.osgi.framework.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) SearchException(org.opencastproject.search.api.SearchException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Date(java.util.Date) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) ServiceException(org.osgi.framework.ServiceException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Tuple(org.opencastproject.util.data.Tuple)

Aggregations

Tuple (org.opencastproject.util.data.Tuple)28 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 NotFoundException (org.opencastproject.util.NotFoundException)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 URI (java.net.URI)6 Job (org.opencastproject.job.api.Job)5 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)5 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 LaidOutElement (org.opencastproject.composer.api.LaidOutElement)4 Dimension (org.opencastproject.composer.layout.Dimension)4 Catalog (org.opencastproject.mediapackage.Catalog)4 AccessControlList (org.opencastproject.security.api.AccessControlList)4 File (java.io.File)3 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 MultiShapeLayout (org.opencastproject.composer.layout.MultiShapeLayout)3