use of io.dockstore.webservice.jdbi.WorkflowDAO in project dockstore by dockstore.
the class WorkflowIT method setup.
@Before
public void setup() {
DockstoreWebserviceApplication application = SUPPORT.getApplication();
SessionFactory sessionFactory = application.getHibernate().getSessionFactory();
this.workflowDAO = new WorkflowDAO(sessionFactory);
this.workflowVersionDAO = new WorkflowVersionDAO(sessionFactory);
this.fileDAO = new FileDAO(sessionFactory);
// used to allow us to use workflowDAO outside of the web service
Session session = application.getHibernate().getSessionFactory().openSession();
ManagedSessionContext.bind(session);
}
use of io.dockstore.webservice.jdbi.WorkflowDAO in project dockstore by dockstore.
the class UserResource method deleteSelfFromEntries.
private void deleteSelfFromEntries(User user) {
user.getEntries().stream().filter(e -> e.getUsers().size() == 1 && !e.getIsPublished()).forEach(entry -> {
EntryDAO entryDAO;
if (entry instanceof Workflow) {
entryDAO = workflowDAO;
} else if (entry instanceof Tool) {
entryDAO = toolDAO;
} else {
throw new CustomWebApplicationException(MessageFormat.format("Unexpected entry type {0}", entry.getClass().toString()), HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
eventDAO.deleteEventByEntryID(entry.getId());
entryDAO.delete(entry);
});
}
use of io.dockstore.webservice.jdbi.WorkflowDAO in project dockstore by dockstore.
the class ServiceIT method setup.
@Before
public void setup() {
DockstoreWebserviceApplication application = SUPPORT.getApplication();
SessionFactory sessionFactory = application.getHibernate().getSessionFactory();
this.workflowDAO = new WorkflowDAO(sessionFactory);
this.serviceDAO = new ServiceDAO(sessionFactory);
this.userDAO = new UserDAO(sessionFactory);
this.fileDAO = new FileDAO(sessionFactory);
// non-confidential test database sequences seem messed up and need to be iterated past, but other tests may depend on ids
testingPostgres.runUpdateStatement("alter sequence enduser_id_seq increment by 50 restart with 100");
testingPostgres.runUpdateStatement("alter sequence token_id_seq increment by 50 restart with 100");
// used to allow us to use tokenDAO outside of the web service
this.session = application.getHibernate().getSessionFactory().openSession();
ManagedSessionContext.bind(session);
}
use of io.dockstore.webservice.jdbi.WorkflowDAO in project dockstore by dockstore.
the class DockstoreWebserviceApplication method run.
@Override
public void run(DockstoreWebserviceConfiguration configuration, Environment environment) {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setSchemes(new String[] { configuration.getExternalConfig().getScheme() });
String portFragment = configuration.getExternalConfig().getPort() == null ? "" : ":" + configuration.getExternalConfig().getPort();
beanConfig.setHost(configuration.getExternalConfig().getHostname() + portFragment);
beanConfig.setBasePath(MoreObjects.firstNonNull(configuration.getExternalConfig().getBasePath(), "/"));
beanConfig.setResourcePackage("io.dockstore.webservice.resources,io.swagger.api,io.openapi.api");
beanConfig.setScan(true);
final DefaultPluginManager languagePluginManager = LanguagePluginManager.getInstance(getFilePluginLocation(configuration));
describeAvailableLanguagePlugins(languagePluginManager);
LanguageHandlerFactory.setLanguagePluginManager(languagePluginManager);
final PublicStateManager publicStateManager = PublicStateManager.getInstance();
publicStateManager.setConfig(configuration);
final TRSListener trsListener = new TRSListener();
publicStateManager.addListener(trsListener);
environment.jersey().property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
environment.jersey().register(new JsonProcessingExceptionMapper(true));
final TemplateHealthCheck healthCheck = new TemplateHealthCheck(configuration.getTemplate());
environment.healthChecks().register("template", healthCheck);
final ElasticSearchHealthCheck elasticSearchHealthCheck = new ElasticSearchHealthCheck(new ToolsExtendedApi());
environment.healthChecks().register("elasticSearch", elasticSearchHealthCheck);
environment.lifecycle().manage(new ElasticSearchHelper(configuration.getEsConfiguration()));
final UserDAO userDAO = new UserDAO(hibernate.getSessionFactory());
final TokenDAO tokenDAO = new TokenDAO(hibernate.getSessionFactory());
final DeletedUsernameDAO deletedUsernameDAO = new DeletedUsernameDAO(hibernate.getSessionFactory());
final ToolDAO toolDAO = new ToolDAO(hibernate.getSessionFactory());
final FileDAO fileDAO = new FileDAO(hibernate.getSessionFactory());
final WorkflowDAO workflowDAO = new WorkflowDAO(hibernate.getSessionFactory());
final TagDAO tagDAO = new TagDAO(hibernate.getSessionFactory());
final EventDAO eventDAO = new EventDAO(hibernate.getSessionFactory());
final VersionDAO versionDAO = new VersionDAO(hibernate.getSessionFactory());
final BioWorkflowDAO bioWorkflowDAO = new BioWorkflowDAO(hibernate.getSessionFactory());
LOG.info("Cache directory for OkHttp is: " + cache.directory().getAbsolutePath());
LOG.info("This is our custom logger saying that we're about to load authenticators");
// setup authentication to allow session access in authenticators, see https://github.com/dropwizard/dropwizard/pull/1361
SimpleAuthenticator authenticator = new UnitOfWorkAwareProxyFactory(getHibernate()).create(SimpleAuthenticator.class, new Class[] { TokenDAO.class, UserDAO.class }, new Object[] { tokenDAO, userDAO });
CachingAuthenticator<String, User> cachingAuthenticator = new CachingAuthenticator<>(environment.metrics(), authenticator, configuration.getAuthenticationCachePolicy());
environment.jersey().register(new AuthDynamicFeature(new OAuthCredentialAuthFilter.Builder<User>().setAuthenticator(cachingAuthenticator).setAuthorizer(new SimpleAuthorizer()).setPrefix("Bearer").setRealm("Dockstore User Authentication").buildAuthFilter()));
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
environment.jersey().register(RolesAllowedDynamicFeature.class);
final HttpClient httpClient = new HttpClientBuilder(environment).using(configuration.getHttpClientConfiguration()).build(getName());
final PermissionsInterface authorizer = PermissionsFactory.createAuthorizer(tokenDAO, configuration);
final EntryResource entryResource = new EntryResource(tokenDAO, toolDAO, versionDAO, userDAO, configuration);
environment.jersey().register(entryResource);
final WorkflowResource workflowResource = new WorkflowResource(httpClient, hibernate.getSessionFactory(), authorizer, entryResource, configuration);
environment.jersey().register(workflowResource);
final ServiceResource serviceResource = new ServiceResource(httpClient, hibernate.getSessionFactory(), entryResource, configuration);
environment.jersey().register(serviceResource);
// Note workflow resource must be passed to the docker repo resource, as the workflow resource refresh must be called for checker workflows
final DockerRepoResource dockerRepoResource = new DockerRepoResource(httpClient, hibernate.getSessionFactory(), configuration, workflowResource, entryResource);
environment.jersey().register(dockerRepoResource);
environment.jersey().register(new DockerRepoTagResource(toolDAO, tagDAO, eventDAO, versionDAO));
environment.jersey().register(new TokenResource(tokenDAO, userDAO, deletedUsernameDAO, httpClient, cachingAuthenticator, configuration));
environment.jersey().register(new UserResource(httpClient, getHibernate().getSessionFactory(), workflowResource, serviceResource, dockerRepoResource, cachingAuthenticator, authorizer, configuration));
MetadataResourceHelper.init(configuration);
environment.jersey().register(new UserResourceDockerRegistries(getHibernate().getSessionFactory()));
environment.jersey().register(new MetadataResource(getHibernate().getSessionFactory(), configuration));
environment.jersey().register(new HostedToolResource(getHibernate().getSessionFactory(), authorizer, configuration.getLimitConfig()));
environment.jersey().register(new HostedWorkflowResource(getHibernate().getSessionFactory(), authorizer, configuration.getLimitConfig()));
environment.jersey().register(new OrganizationResource(getHibernate().getSessionFactory()));
environment.jersey().register(new LambdaEventResource(getHibernate().getSessionFactory()));
environment.jersey().register(new NotificationResource(getHibernate().getSessionFactory()));
environment.jersey().register(new CollectionResource(getHibernate().getSessionFactory()));
environment.jersey().register(new EventResource(eventDAO, userDAO));
environment.jersey().register(new ToolTesterResource(configuration));
environment.jersey().register(new CloudInstanceResource(getHibernate().getSessionFactory()));
// disable odd extra endpoints showing up
final SwaggerConfiguration swaggerConfiguration = new SwaggerConfiguration().prettyPrint(true);
swaggerConfiguration.setIgnoredRoutes(Lists.newArrayList("/application.wadl", "/pprof"));
BaseOpenApiResource openApiResource = new OpenApiResource().openApiConfiguration(swaggerConfiguration);
environment.jersey().register(openApiResource);
final AliasResource aliasResource = new AliasResource(hibernate.getSessionFactory(), workflowResource);
environment.jersey().register(aliasResource);
// attach the container dao statically to avoid too much modification of generated code
ToolsApiServiceImpl.setToolDAO(toolDAO);
ToolsApiServiceImpl.setWorkflowDAO(workflowDAO);
ToolsApiServiceImpl.setBioWorkflowDAO(bioWorkflowDAO);
ToolsApiServiceImpl.setFileDAO(fileDAO);
ToolsApiServiceImpl.setConfig(configuration);
ToolsApiServiceImpl.setTrsListener(trsListener);
ToolsApiExtendedServiceImpl.setStateManager(publicStateManager);
ToolsApiExtendedServiceImpl.setToolDAO(toolDAO);
ToolsApiExtendedServiceImpl.setWorkflowDAO(workflowDAO);
ToolsApiExtendedServiceImpl.setConfig(configuration);
DOIGeneratorFactory.setConfig(configuration);
GoogleHelper.setConfig(configuration);
registerAPIsAndMisc(environment);
// optional CORS support
// Enable CORS headers
// final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class);
final FilterHolder filterHolder = environment.getApplicationContext().addFilter(CrossOriginFilter.class, "/*", EnumSet.of(REQUEST));
filterHolder.setInitParameter(ACCESS_CONTROL_ALLOW_METHODS_HEADER, "GET,POST,DELETE,PUT,OPTIONS,PATCH");
filterHolder.setInitParameter(ALLOWED_ORIGINS_PARAM, "*");
filterHolder.setInitParameter(ALLOWED_METHODS_PARAM, "GET,POST,DELETE,PUT,OPTIONS,PATCH");
filterHolder.setInitParameter(ALLOWED_HEADERS_PARAM, "Authorization, X-Auth-Username, X-Auth-Password, X-Requested-With,Content-Type,Accept,Origin,Access-Control-Request-Headers,cache-control");
// Initialize GitHub App Installation Access Token cache
CacheConfigManager cacheConfigManager = CacheConfigManager.getInstance();
cacheConfigManager.initCache();
}
Aggregations