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;
}
};
}
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();
}
};
}
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;
}
};
}
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();
}
};
}
Aggregations