Search in sources :

Example 1 with Database

use of org.opencastproject.assetmanager.impl.persistence.Database in project opencast by opencast.

the class SchedulerServiceImplTest method mkAssetManager.

AssetManager mkAssetManager() throws Exception {
    final PersistenceEnv penv = PersistenceEnvs.mk(mkEntityManagerFactory("org.opencastproject.assetmanager.impl"));
    final Database db = new Database(penv);
    return new AbstractAssetManager() {

        @Override
        public HttpAssetProvider getHttpAssetProvider() {
            // identity provider
            return new HttpAssetProvider() {

                @Override
                public Snapshot prepareForDelivery(Snapshot snapshot) {
                    return snapshot;
                }
            };
        }

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

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

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

        @Override
        protected String getCurrentOrgId() {
            return DefaultOrganization.DEFAULT_ORGANIZATION_ID;
        }
    };
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) HttpAssetProvider(org.opencastproject.assetmanager.impl.HttpAssetProvider) AbstractAssetManager(org.opencastproject.assetmanager.impl.AbstractAssetManager) PersistenceEnv(org.opencastproject.util.persistencefn.PersistenceEnv) Database(org.opencastproject.assetmanager.impl.persistence.Database)

Example 2 with Database

use of org.opencastproject.assetmanager.impl.persistence.Database in project opencast by opencast.

the class AssetManagerTestBase method mkAbstractAssetManager.

/**
 * Create a new test asset manager.
 */
protected AbstractAssetManager mkAbstractAssetManager() throws Exception {
    penv = PersistenceEnvs.mkTestEnvFromSystemProperties(PERSISTENCE_UNIT);
    // empty database
    penv.tx(new Fn<EntityManager, Object>() {

        @Override
        public Object apply(EntityManager entityManager) {
            Queries.sql.update(entityManager, "delete from oc_assets_asset");
            Queries.sql.update(entityManager, "delete from oc_assets_properties");
            Queries.sql.update(entityManager, "delete from oc_assets_snapshot");
            Queries.sql.update(entityManager, "delete from oc_assets_version_claim");
            return null;
        }
    });
    final Database db = new Database(penv);
    // 
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore-a.xml").get()).anyTimes();
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class), EasyMock.anyBoolean())).andAnswer(() -> {
        File tmp = tempFolder.newFile();
        FileUtils.copyFile(new File(getClass().getResource("/dublincore-a.xml").toURI()), tmp);
        return tmp;
    }).anyTimes();
    EasyMock.replay(workspace);
    // 
    final AssetStore assetStore = mkAssetStore();
    // 
    return new AbstractAssetManager() {

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

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

        @Override
        public HttpAssetProvider getHttpAssetProvider() {
            // identity provider
            return new HttpAssetProvider() {

                @Override
                public Snapshot prepareForDelivery(Snapshot snapshot) {
                    return snapshot;
                }
            };
        }

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

        @Override
        protected String getCurrentOrgId() {
            return AssetManagerTestBase.this.getCurrentOrgId();
        }
    };
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) EntityManager(javax.persistence.EntityManager) Database(org.opencastproject.assetmanager.impl.persistence.Database) AssetStore(org.opencastproject.assetmanager.impl.storage.AssetStore) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace)

Example 3 with Database

use of org.opencastproject.assetmanager.impl.persistence.Database in project opencast by opencast.

the class TestTasksEndpoint method mkAssetManager.

AssetManager mkAssetManager(final Workspace workspace) throws Exception {
    final PersistenceEnv penv = PersistenceEnvs.mk(mkEntityManagerFactory("org.opencastproject.assetmanager.impl"));
    final Database db = new Database(penv);
    return new AbstractAssetManager() {

        @Override
        public HttpAssetProvider getHttpAssetProvider() {
            // identity provider
            return new HttpAssetProvider() {

                @Override
                public Snapshot prepareForDelivery(Snapshot snapshot) {
                    return snapshot;
                }
            };
        }

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

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

        @Override
        public AssetStore getAssetStore() {
            return mkAssetStore(workspace);
        }

        @Override
        protected String getCurrentOrgId() {
            return DefaultOrganization.DEFAULT_ORGANIZATION_ID;
        }
    };
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) HttpAssetProvider(org.opencastproject.assetmanager.impl.HttpAssetProvider) AbstractAssetManager(org.opencastproject.assetmanager.impl.AbstractAssetManager) PersistenceEnv(org.opencastproject.util.persistencefn.PersistenceEnv) Database(org.opencastproject.assetmanager.impl.persistence.Database)

Example 4 with Database

use of org.opencastproject.assetmanager.impl.persistence.Database 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)

Aggregations

Database (org.opencastproject.assetmanager.impl.persistence.Database)4 Snapshot (org.opencastproject.assetmanager.api.Snapshot)3 AbstractAssetManager (org.opencastproject.assetmanager.impl.AbstractAssetManager)2 HttpAssetProvider (org.opencastproject.assetmanager.impl.HttpAssetProvider)2 PersistenceEnv (org.opencastproject.util.persistencefn.PersistenceEnv)2 File (java.io.File)1 EntityManager (javax.persistence.EntityManager)1 AssetManager (org.opencastproject.assetmanager.api.AssetManager)1 AssetStore (org.opencastproject.assetmanager.impl.storage.AssetStore)1 Workspace (org.opencastproject.workspace.api.Workspace)1