Search in sources :

Example 56 with MediaPackage

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

the class SearchServiceImplTest method testDeleteMediaPackage.

/**
 * Test removal from the search index.
 */
@Test
public void testDeleteMediaPackage() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
    // Make sure our mocked ACL has the read and write permission
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    // Now take the role away from the user
    userResponder.setResponse(userWithoutPermissions);
    Map<String, Integer> servers = new HashMap<String, Integer>();
    servers.put("http://localhost", 8080);
    organizationResponder.setResponse(new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, servers, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, null));
    // Try to delete it
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
    assertEquals("Unauthorized user was able to delete a mediapackage", Boolean.FALSE.toString(), job.getPayload());
    // Second try with a "fixed" roleset
    User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
    userResponder.setResponse(adminUser);
    Date deletedDate = new Date();
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Unauthorized user was able to delete a mediapackage", Job.Status.FINISHED, job.getStatus());
    // Now go back to the original security service and user
    userResponder.setResponse(defaultUser);
    organizationResponder.setResponse(defaultOrganization);
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/1");
    assertEquals(0, service.getByQuery(q).size());
    // Clear the ID requirement
    q.withId(null);
    assertEquals(0, service.getByQuery(q).size());
    q = new SearchQuery();
    q.withDeletedSince(deletedDate);
    assertEquals(1, service.getByQuery(q).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) JobBarrier(org.opencastproject.job.api.JobBarrier) Date(java.util.Date) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 57 with MediaPackage

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

the class SearchServiceImplTest method getMediaPackage.

private MediaPackage getMediaPackage(String path) throws MediaPackageException {
    MediaPackageBuilderFactory builderFactory = MediaPackageBuilderFactory.newInstance();
    MediaPackageBuilder mediaPackageBuilder = builderFactory.newMediaPackageBuilder();
    URL rootUrl = SearchServiceImplTest.class.getResource("/");
    mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(rootUrl));
    // Load the simple media package
    MediaPackage mediaPackage = null;
    InputStream is = null;
    try {
        is = SearchServiceImplTest.class.getResourceAsStream(path);
        mediaPackage = mediaPackageBuilder.loadFromXml(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return mediaPackage;
}
Also used : DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageBuilderFactory(org.opencastproject.mediapackage.MediaPackageBuilderFactory) URL(java.net.URL)

Example 58 with MediaPackage

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

the class SearchServiceImplTest method testSearchForPartialStrings.

@Test
public void testSearchForPartialStrings() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.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());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmo")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmos")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosp")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosph")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmosphe")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospher")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Atmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("atmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheric")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("tmospheri")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Vegetatio")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("vege")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("egetatio")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("egetation")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("lecture")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("lectur")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ecture")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ectur")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Science")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Scienc")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ience")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("cienc")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("ducti")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Institute")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitute")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("nstitut")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("Institut")).size());
    assertEquals(1, service.getByQuery(new SearchQuery().withText("2008-03-05")).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) Test(org.junit.Test)

Example 59 with MediaPackage

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

the class SolrRequester method createSearchResult.

/**
 * Creates a search result from a given solr response.
 *
 * @param query
 *          The solr query.
 * @return The search result.
 * @throws SolrServerException
 *           if the solr server is not working as expected
 */
private SearchResult createSearchResult(final SolrQuery query) throws SolrServerException {
    // Execute the query and try to get hold of a query response
    QueryResponse solrResponse = null;
    try {
        solrResponse = solrServer.query(query);
    } catch (Exception e) {
        throw new SolrServerException(e);
    }
    // Create and configure the query result
    final SearchResultImpl result = new SearchResultImpl(query.getQuery());
    result.setSearchTime(solrResponse.getQTime());
    result.setOffset(solrResponse.getResults().getStart());
    result.setLimit(solrResponse.getResults().size());
    result.setTotal(solrResponse.getResults().getNumFound());
    // Walk through response and create new items with title, creator, etc:
    for (final SolrDocument doc : solrResponse.getResults()) {
        final SearchResultItemImpl item = SearchResultItemImpl.fill(new SearchResultItem() {

            private final String dfltString = null;

            @Override
            public String getId() {
                return Schema.getId(doc);
            }

            /**
             * {@inheritDoc}
             *
             * @see org.opencastproject.search.api.SearchResultItem#getOrganization()
             */
            @Override
            public String getOrganization() {
                return Schema.getOrganization(doc);
            }

            @Override
            public MediaPackage getMediaPackage() {
                MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
                if (serializer != null)
                    builder.setSerializer(serializer);
                String mediaPackageFieldValue = Schema.getOcMediapackage(doc);
                if (mediaPackageFieldValue != null) {
                    try {
                        return builder.loadFromXml(mediaPackageFieldValue);
                    } catch (Exception e) {
                        logger.warn("Unable to read media package from search result", e);
                    }
                }
                return null;
            }

            @Override
            public long getDcExtent() {
                if (getType().equals(SearchResultItemType.AudioVisual)) {
                    Long extent = Schema.getDcExtent(doc);
                    if (extent != null)
                        return extent;
                }
                return -1;
            }

            @Override
            public String getDcTitle() {
                final List<DField<String>> titles = Schema.getDcTitle(doc);
                // try to return the first title without any language information first...
                return head(filter(titles, new Predicate<DField<String>>() {

                    @Override
                    public Boolean apply(DField<String> f) {
                        return f.getSuffix().equals(Schema.LANGUAGE_UNDEFINED);
                    }
                })).map(new Function<DField<String>, String>() {

                    @Override
                    public String apply(DField<String> f) {
                        return f.getValue();
                    }
                }).getOrElse(new Function0<String>() {

                    @Override
                    public String apply() {
                        // ... since none is present return the first arbitrary title
                        return Schema.getFirst(titles, dfltString);
                    }
                });
            }

            @Override
            public String getDcSubject() {
                return Schema.getFirst(Schema.getDcSubject(doc), dfltString);
            }

            @Override
            public String getDcDescription() {
                return Schema.getFirst(Schema.getDcDescription(doc), dfltString);
            }

            @Override
            public String getDcCreator() {
                return Schema.getFirst(Schema.getDcCreator(doc), dfltString);
            }

            @Override
            public String getDcPublisher() {
                return Schema.getFirst(Schema.getDcPublisher(doc), dfltString);
            }

            @Override
            public String getDcContributor() {
                return Schema.getFirst(Schema.getDcContributor(doc), dfltString);
            }

            @Override
            public String getDcAbstract() {
                return null;
            }

            @Override
            public Date getDcCreated() {
                return Schema.getDcCreated(doc);
            }

            @Override
            public Date getDcAvailableFrom() {
                return Schema.getDcAvailableFrom(doc);
            }

            @Override
            public Date getDcAvailableTo() {
                return Schema.getDcAvailableTo(doc);
            }

            @Override
            public String getDcLanguage() {
                return Schema.getDcLanguage(doc);
            }

            @Override
            public String getDcRightsHolder() {
                return Schema.getFirst(Schema.getDcRightsHolder(doc), dfltString);
            }

            @Override
            public String getDcSpatial() {
                return Schema.getFirst(Schema.getDcSpatial(doc), dfltString);
            }

            @Override
            public String getDcTemporal() {
                return null;
            }

            @Override
            public String getDcIsPartOf() {
                return Schema.getDcIsPartOf(doc);
            }

            @Override
            public String getDcReplaces() {
                return Schema.getDcReplaces(doc);
            }

            @Override
            public String getDcType() {
                return Schema.getDcType(doc);
            }

            @Override
            public String getDcAccessRights() {
                return Schema.getFirst(Schema.getDcAccessRights(doc), dfltString);
            }

            @Override
            public String getDcLicense() {
                return Schema.getFirst(Schema.getDcLicense(doc), dfltString);
            }

            @Override
            public String getOcMediapackage() {
                return Schema.getOcMediapackage(doc);
            }

            @Override
            public SearchResultItemType getType() {
                String t = Schema.getOcMediatype(doc);
                return t != null ? SearchResultItemType.valueOf(t) : null;
            }

            @Override
            public String[] getKeywords() {
                if (getType().equals(SearchResultItemType.AudioVisual)) {
                    String k = Schema.getOcKeywords(doc);
                    return k != null ? k.split(" ") : new String[0];
                } else
                    return new String[0];
            }

            @Override
            public String getCover() {
                return Schema.getOcCover(doc);
            }

            @Override
            public Date getModified() {
                return Schema.getOcModified(doc);
            }

            @Override
            public double getScore() {
                return Schema.getScore(doc);
            }

            @Override
            public MediaSegment[] getSegments() {
                if (SearchResultItemType.AudioVisual.equals(getType()))
                    return createSearchResultSegments(doc, query).toArray(new MediaSegmentImpl[0]);
                else
                    return new MediaSegmentImpl[0];
            }
        });
        // Add the item to the result set
        result.addItem(item);
    }
    return result;
}
Also used : SearchResultItemImpl(org.opencastproject.search.api.SearchResultItemImpl) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SearchResultItem(org.opencastproject.search.api.SearchResultItem) Function0(org.opencastproject.util.data.Function0) SearchResultItemType(org.opencastproject.search.api.SearchResultItem.SearchResultItemType) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) Date(java.util.Date) SolrDocument(org.apache.solr.common.SolrDocument) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SearchResultImpl(org.opencastproject.search.api.SearchResultImpl) MediaSegmentImpl(org.opencastproject.search.api.MediaSegmentImpl) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 60 with MediaPackage

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

the class SearchServiceDatabaseImpl method getAllMediaPackages.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getAllMediaPackages()
 */
@Override
@SuppressWarnings("unchecked")
public Iterator<Tuple<MediaPackage, String>> getAllMediaPackages() throws SearchServiceDatabaseException {
    List<SearchEntity> searchEntities = null;
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query query = em.createNamedQuery("Search.findAll");
        searchEntities = (List<SearchEntity>) query.getResultList();
    } catch (Exception e) {
        logger.error("Could not retrieve all episodes: {}", e.getMessage());
        throw new SearchServiceDatabaseException(e);
    } finally {
        em.close();
    }
    List<Tuple<MediaPackage, String>> mediaPackageList = new LinkedList<Tuple<MediaPackage, String>>();
    try {
        for (SearchEntity entity : searchEntities) {
            MediaPackage mediaPackage = MediaPackageParser.getFromXml(entity.getMediaPackageXML());
            mediaPackageList.add(Tuple.tuple(mediaPackage, entity.getOrganization()));
        }
    } catch (Exception e) {
        logger.error("Could not parse series entity: {}", e.getMessage());
        throw new SearchServiceDatabaseException(e);
    }
    return mediaPackageList.iterator();
}
Also used : EntityManager(javax.persistence.EntityManager) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NoResultException(javax.persistence.NoResultException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Tuple(org.opencastproject.util.data.Tuple) LinkedList(java.util.LinkedList)

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