Search in sources :

Example 26 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SeriesServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = SeriesItem.SERIES_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
    try {
        final int total = persistence.countSeries();
        logger.info("Re-populating '{}' index with series. There are {} series to add to the index.", indexName, total);
        final int responseInterval = (total < 100) ? 1 : (total / 100);
        List<SeriesEntity> databaseSeries = persistence.getAllSeries();
        int current = 1;
        for (SeriesEntity series : databaseSeries) {
            Organization organization = orgDirectory.getOrganization(series.getOrganization());
            SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Function0.X<Void>() {

                @Override
                public Void xapply() throws Exception {
                    String id = series.getSeriesId();
                    logger.trace("Adding series '{}' for org '{}'", id, series.getOrganization());
                    DublinCoreCatalog catalog = DublinCoreXmlFormat.read(series.getDublinCoreXML());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(catalog));
                    AccessControlList acl = AccessControlParser.parseAcl(series.getAccessControl());
                    if (acl != null) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateAcl(id, acl));
                    }
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateOptOut(id, series.isOptOut()));
                    for (Entry<String, String> property : persistence.getSeriesProperties(id).entrySet()) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateProperty(id, property.getKey(), property.getValue()));
                    }
                    return null;
                }
            });
            if ((current % responseInterval == 0) || (current == total)) {
                logger.info("Initializing {} series index rebuild {}/{}: {} percent", indexName, current, total, current * 100 / total);
            }
            current++;
        }
        logger.info("Finished initializing '{}' index rebuild", indexName);
    } catch (Exception e) {
        logger.warn("Unable to index series instances:", e);
        throw new ServiceException(e.getMessage());
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Series));
        }
    });
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) SeriesEntity(org.opencastproject.series.impl.persistence.SeriesEntity) Function0(org.opencastproject.util.data.Function0) ServiceException(org.osgi.framework.ServiceException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) FunctionException(org.opencastproject.util.data.FunctionException) Entry(java.util.Map.Entry) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 27 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SearchResultItem(org.opencastproject.search.api.SearchResultItem) SearchException(org.opencastproject.search.api.SearchException) NotFoundException(org.opencastproject.util.NotFoundException) SearchResult(org.opencastproject.search.api.SearchResult) Attachment(org.opencastproject.mediapackage.Attachment) IOException(java.io.IOException) JobBarrier(org.opencastproject.job.api.JobBarrier) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Result(org.opencastproject.job.api.JobBarrier.Result) SearchResult(org.opencastproject.search.api.SearchResult) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 28 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class EventsLoader method getBasicMediaPackage.

private MediaPackage getBasicMediaPackage(EventEntry event) throws Exception {
    URL baseMediapackageUrl = EventsLoader.class.getResource("/base_mediapackage.xml");
    MediaPackage mediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(baseMediapackageUrl));
    DublinCoreCatalog episodeDublinCore = getBasicEpisodeDublinCore(event);
    mediaPackage.setDate(event.getRecordingDate());
    mediaPackage.setIdentifier(new IdImpl(episodeDublinCore.getFirst(DublinCoreCatalog.PROPERTY_IDENTIFIER)));
    mediaPackage.setTitle(event.getTitle());
    addDublinCoreCatalog(IOUtils.toInputStream(episodeDublinCore.toXmlString(), "UTF-8"), MediaPackageElements.EPISODE, mediaPackage);
    // assign to a series
    if (event.getSeries().isSome()) {
        DublinCoreCatalog seriesCatalog = seriesService.getSeries(event.getSeries().get());
        mediaPackage.setSeries(event.getSeries().get());
        mediaPackage.setSeriesTitle(seriesCatalog.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
        addDublinCoreCatalog(IOUtils.toInputStream(seriesCatalog.toXmlString(), "UTF-8"), MediaPackageElements.SERIES, mediaPackage);
        AccessControlList acl = seriesService.getSeriesAccessControl(event.getSeries().get());
        if (acl != null) {
            authorizationService.setAcl(mediaPackage, AclScope.Series, acl);
        }
    }
    // Set track URI's to demo file
    for (Track track : mediaPackage.getTracks()) {
        InputStream in = null;
        try {
            in = getClass().getResourceAsStream("/av.mov");
            URI uri = workspace.put(mediaPackage.getIdentifier().compact(), track.getIdentifier(), FilenameUtils.getName(track.toString()), in);
            track.setURI(uri);
            track.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, getClass().getResourceAsStream("/av.mov")));
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return mediaPackage;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) URI(java.net.URI) URL(java.net.URL) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Track(org.opencastproject.mediapackage.Track)

Example 29 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class LiveScheduleServiceImplTest method testUpdateLiveEvent.

@Test
public void testUpdateLiveEvent() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp-with-live.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    setUpAssetManager(mp);
    mpURI = LiveScheduleServiceImplTest.class.getResource("/live-mp.xml").toURI();
    MediaPackage previousMp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/episode.xml").toURI();
    DublinCoreCatalog episodeDC = DublinCores.read(catalogURI.toURL().openStream());
    catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
    DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
    EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode_updated.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job);
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    Job jobPub = createJob(2L, "anything", "anything");
    Capture<MediaPackage> capturedMp = Capture.newInstance();
    EasyMock.expect(searchService.add(EasyMock.capture(capturedMp))).andReturn(jobPub);
    EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job).anyTimes();
    Job jobRetract = createJob(3L, "anything", "anything");
    EasyMock.expect(downloadDistributionService.retract(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class))).andReturn(jobRetract);
    EasyMock.expect(serviceRegistry.getJob(3L)).andReturn(jobRetract).anyTimes();
    replayServices();
    service.setDownloadDistributionService(downloadDistributionService);
    // Capture agent change
    episodeDC.set(DublinCore.PROPERTY_SPATIAL, DublinCoreValue.mk("another_ca"));
    // Duration change
    episodeDC.set(DublinCore.PROPERTY_TEMPORAL, DublinCoreValue.mk("start=2017-10-12T19:00:00Z;end=2017-10-12T19:02:00Z; scheme=W3C-DTF;"));
    Assert.assertTrue(service.updateLiveEvent(previousMp, episodeDC));
    // Check published live media package
    MediaPackage searchMp = capturedMp.getValue();
    Assert.assertEquals(MP_ID, searchMp.getIdentifier().compact());
    Assert.assertEquals(120000L, searchMp.getDuration().longValue());
    Assert.assertEquals(2, searchMp.getCatalogs().length);
    assertExpectedLiveTracks(searchMp.getTracks(), 120000L, "another_ca", "_suffix", false);
    Assert.assertEquals(0, searchMp.getPublications().length);
}
Also used : Set(java.util.Set) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Test(org.junit.Test)

Example 30 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class LiveScheduleServiceImplTest method testUpdateLiveEventNoChange.

@Test
public void testUpdateLiveEventNoChange() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp-with-live.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    setUpAssetManager(mp);
    mpURI = LiveScheduleServiceImplTest.class.getResource("/live-mp.xml").toURI();
    MediaPackage previousMp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/episode.xml").toURI();
    DublinCoreCatalog episodeDC = DublinCores.read(catalogURI.toURL().openStream());
    replayServices();
    service.getSnapshotVersionCache().put(MP_ID, version);
    Assert.assertFalse(service.updateLiveEvent(previousMp, episodeDC));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) URI(java.net.URI) Test(org.junit.Test)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14