Search in sources :

Example 1 with AssetManager

use of org.opencastproject.assetmanager.api.AssetManager in project opencast by opencast.

the class TestRestService method newAssetManager.

private static AssetManager newAssetManager() {
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    try {
        EasyMock.expect(snapshot.getMediaPackage()).andReturn(new MediaPackageBuilderImpl().createNew()).anyTimes();
    } catch (MediaPackageException e) {
        throw new RuntimeException(e);
    }
    ARecord record = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(record.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
    AResult result = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(result.getRecords()).andReturn($(record)).anyTimes();
    ASelectQuery select = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(select.where(EasyMock.anyObject(Predicate.class))).andReturn(select).anyTimes();
    EasyMock.expect(select.run()).andReturn(result).anyTimes();
    Predicate predicate = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(predicate.and(EasyMock.anyObject(Predicate.class))).andReturn(predicate).anyTimes();
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    VersionField version = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(query.version()).andReturn(version).anyTimes();
    EasyMock.expect(query.mediaPackageId(EasyMock.anyString())).andReturn(predicate).anyTimes();
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(select).anyTimes();
    AssetManager assetManager = EasyMock.createNiceMock(AssetManager.class);
    EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
    EasyMock.replay(assetManager, version, query, predicate, select, result, record, snapshot);
    return assetManager;
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AssetManager(org.opencastproject.assetmanager.api.AssetManager) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) VersionField(org.opencastproject.assetmanager.api.query.VersionField) AResult(org.opencastproject.assetmanager.api.query.AResult) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Predicate(org.opencastproject.assetmanager.api.query.Predicate)

Example 2 with AssetManager

use of org.opencastproject.assetmanager.api.AssetManager in project opencast by opencast.

the class LiveScheduleServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    mimeType = MimeTypes.parseMimeType(MIME_TYPE);
    // Osgi Services
    serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    searchService = EasyMock.createNiceMock(SearchService.class);
    seriesService = EasyMock.createNiceMock(SeriesService.class);
    captureAgentService = EasyMock.createNiceMock(CaptureAgentStateService.class);
    EasyMock.expect(captureAgentService.getAgentCapabilities("demo-capture-agent")).andReturn(new Properties());
    downloadDistributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    EasyMock.expect(downloadDistributionService.getDistributionType()).andReturn(LiveScheduleServiceImpl.DEFAULT_LIVE_DISTRIBUTION_SERVICE).anyTimes();
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://someUrl"));
    dublinCoreService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
    assetManager = EasyMock.createNiceMock(AssetManager.class);
    authService = new AuthorizationServiceMock();
    organizationService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    Organization defOrg = new DefaultOrganization();
    Map<String, String> orgProps = new HashMap<String, String>();
    orgProps.put(LiveScheduleServiceImpl.PLAYER_PROPERTY, PATH_TO_PLAYER);
    orgProps.put(LiveScheduleServiceImpl.ENGAGE_URL_PROPERTY, ENGAGE_URL);
    org = new JaxbOrganization(ORG_ID, "Test Organization", defOrg.getServers(), defOrg.getAdminRole(), defOrg.getAnonymousRole(), orgProps);
    EasyMock.expect(organizationService.getOrganization(ORG_ID)).andReturn(org).anyTimes();
    // Live service configuration
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(LiveScheduleServiceImpl.LIVE_STREAMING_URL, STREAMING_SERVER_URL);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_MIME_TYPE, "video/x-flv");
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_NAME, STREAM_NAME);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_RESOLUTION, "1920x540,960x270");
    props.put(LiveScheduleServiceImpl.LIVE_TARGET_FLAVORS, "presenter/delivery");
    cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc);
    EasyMock.expect(cc.getProperties()).andReturn(props);
    EasyMock.replay(bc, cc);
    service = new LiveScheduleServiceImpl();
    service.setJobPollingInterval(1L);
    service.setSearchService(searchService);
    service.setSeriesService(seriesService);
    service.setCaptureAgentService(captureAgentService);
    service.setServiceRegistry(serviceRegistry);
    service.setWorkspace(workspace);
    service.setDublinCoreService(dublinCoreService);
    service.setAssetManager(assetManager);
    service.setAuthorizationService(authService);
    service.setOrganizationService(organizationService);
    service.activate(cc);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashMap(java.util.HashMap) Properties(java.util.Properties) URI(java.net.URI) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) SearchService(org.opencastproject.search.api.SearchService) CaptureAgentStateService(org.opencastproject.capture.admin.api.CaptureAgentStateService) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) SeriesService(org.opencastproject.series.api.SeriesService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Workspace(org.opencastproject.workspace.api.Workspace) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 3 with AssetManager

use of org.opencastproject.assetmanager.api.AssetManager in project opencast by opencast.

the class ToolsEndpointTest method testAddSmilToArchive.

/**
 * Test method for {@link ToolsEndpoint#addSmilToArchive(org.opencastproject.mediapackage.MediaPackage, Smil)}
 */
@Test
public void testAddSmilToArchive() throws Exception {
    final String mpId = UUID.randomUUID().toString();
    final URI archiveElementURI = new URI("http://host.tld/archive/cut.smil");
    final String smilId = "s-afe311c6-9161-41f4-98d0-e951fe66d89e";
    Workspace workspace = createNiceMock(Workspace.class);
    expect(workspace.put(same(mpId), same(smilId), same("cut.smil"), anyObject(InputStream.class))).andReturn(archiveElementURI);
    replay(workspace);
    endpoint.setWorkspace(workspace);
    AssetManager assetManager = createNiceMock(AssetManager.class);
    replay(assetManager);
    endpoint.setAssetManager(assetManager);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(new IdImpl(mpId));
    endpoint.addSmilToArchive(mp, smil);
    assertEquals(1, mp.getCatalogs().length);
    assertEquals(smil.getId(), mp.getCatalogs()[0].getIdentifier());
    assertEquals("smil/cutting", mp.getCatalogs()[0].getFlavor().toString());
}
Also used : AssetManager(org.opencastproject.assetmanager.api.AssetManager) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 4 with AssetManager

use of org.opencastproject.assetmanager.api.AssetManager in project opencast by opencast.

the class OsgiAssetManager method activate.

/**
 * OSGi callback.
 */
public void activate(ComponentContext cc) {
    logger.info("Activating AssetManager");
    final Database db = new Database(PersistenceEnvs.mk(emf));
    final String systemUserName = SecurityUtil.getSystemUserName(cc);
    // create the core asset manager
    final AssetManager core = new AbstractAssetManager() {

        @Override
        public Database getDb() {
            return db;
        }

        @Override
        public HttpAssetProvider getHttpAssetProvider() {
            return httpAssetProvider;
        }

        @Override
        public AssetStore getAssetStore() {
            return assetStore;
        }

        @Override
        protected Workspace getWorkspace() {
            return workspace;
        }

        @Override
        protected String getCurrentOrgId() {
            return secSvc.getOrganization().getId();
        }
    };
    // compose with ActiveMQ messaging
    final AssetManagerWithMessaging withMessaging = new AssetManagerWithMessaging(core, messageSender, messageReceiver, authSvc, orgDir, secSvc, workspace, systemUserName);
    // compose with security
    delegate = new AssetManagerWithSecurity(withMessaging, authSvc, secSvc);
    // collect all objects that need to be closed
    toClose = new AutoCloseable() {

        @Override
        public void close() throws Exception {
            withMessaging.close();
        }
    };
}
Also used : AssetManager(org.opencastproject.assetmanager.api.AssetManager) Database(org.opencastproject.assetmanager.impl.persistence.Database)

Example 5 with AssetManager

use of org.opencastproject.assetmanager.api.AssetManager in project opencast by opencast.

the class IBMWatsonTranscriptionServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    URI mediaPackageURI = IBMWatsonTranscriptionServiceTest.class.getResource("/mp.xml").toURI();
    mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
    URI audioUrl = IBMWatsonTranscriptionServiceTest.class.getResource("/audio.ogg").toURI();
    audioFile = new File(audioUrl);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(IBMWatsonTranscriptionService.ENABLED_CONFIG, "true");
    props.put(IBMWatsonTranscriptionService.IBM_WATSON_USER_CONFIG, "user");
    props.put(IBMWatsonTranscriptionService.IBM_WATSON_PSW_CONFIG, "psw");
    props.put(IBMWatsonTranscriptionService.COMPLETION_CHECK_BUFFER_CONFIG, 0);
    props.put(IBMWatsonTranscriptionService.MAX_PROCESSING_TIME_CONFIG, 0);
    props.put(IBMWatsonTranscriptionService.NOTIFICATION_EMAIL_CONFIG, "anyone@opencast.org");
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getProperties()).andReturn(props).anyTimes();
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://THIS_SERVER");
    EasyMock.expect(bc.getProperty("org.opencastproject.security.digest.user")).andReturn("matterhorn_system_account");
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    Map<String, String> orgProps = new HashMap<String, String>();
    orgProps.put(IBMWatsonTranscriptionService.ADMIN_URL_PROPERTY, "http://ADMIN_SERVER");
    org = new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, null, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, orgProps);
    User user = new JaxbUser("admin", null, "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
    UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
    IncidentService incident = EasyMock.createNiceMock(IncidentService.class);
    smtpService = EasyMock.createNiceMock(SmtpService.class);
    smtpService.send((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    EasyMock.replay(bc, cc, securityService, orgDirectory, userDirectory, incident, smtpService);
    // Mocks for WorkflowDispatcher test
    assetManager = EasyMock.createNiceMock(AssetManager.class);
    wfService = EasyMock.createNiceMock(WorkflowService.class);
    workspace = EasyMock.createNiceMock(Workspace.class);
    // Database
    database = new TranscriptionDatabase();
    database.setEntityManagerFactory(PersistenceUtil.newTestEntityManagerFactory("org.opencastproject.transcription.ibmwatson.persistence"));
    database.activate(null);
    httpClient = EasyMock.createNiceMock(CloseableHttpClient.class);
    service = new IBMWatsonTranscriptionService() {

        @Override
        protected CloseableHttpClient makeHttpClient() {
            return httpClient;
        }
    };
    ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, incident);
    service.setOrganizationDirectoryService(orgDirectory);
    service.setSecurityService(securityService);
    service.setServiceRegistry(serviceRegistry);
    service.setUserDirectoryService(userDirectory);
    service.setWorkspace(workspace);
    service.setDatabase(database);
    service.setAssetManager(assetManager);
    service.setWorkflowService(wfService);
    service.setSmtpService(smtpService);
    service.activate(cc);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) TranscriptionDatabase(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase) URI(java.net.URI) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) SmtpService(org.opencastproject.kernel.mail.SmtpService) JaxbRole(org.opencastproject.security.api.JaxbRole) JSONObject(org.json.simple.JSONObject) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

AssetManager (org.opencastproject.assetmanager.api.AssetManager)6 URI (java.net.URI)4 Workspace (org.opencastproject.workspace.api.Workspace)4 Before (org.junit.Before)3 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)2 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)2 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)2 BundleContext (org.osgi.framework.BundleContext)2 ComponentContext (org.osgi.service.component.ComponentContext)2 File (java.io.File)1 Properties (java.util.Properties)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1 Snapshot (org.opencastproject.assetmanager.api.Snapshot)1 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)1