Search in sources :

Example 1 with TokenDAO

use of io.dockstore.webservice.jdbi.TokenDAO in project dockstore by dockstore.

the class UserResourceServicesIT method setup.

@Before
public void setup() throws Exception {
    CommonTestUtilities.dropAndCreateWithTestData(SUPPORT, false, DROPWIZARD_CONFIGURATION_FILE_PATH);
    DockstoreWebserviceApplication application = SUPPORT.getApplication();
    SessionFactory sessionFactory = application.getHibernate().getSessionFactory();
    TokenDAO tokenDAO = new TokenDAO(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
    Session session = application.getHibernate().getSessionFactory().openSession();
    ManagedSessionContext.bind(session);
    final Transaction transaction = session.beginTransaction();
    tokenDAO.create(createToken(SUFFIX1, GITHUB_ACCOUNT_USERNAME_1, GITHUB_USER1_ID));
    tokenDAO.create(createToken(SUFFIX2, GITHUB_ACCOUNT_USERNAME_2, GITHUB_USER2_ID));
    transaction.commit();
    session.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) Transaction(org.hibernate.Transaction) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Session(org.hibernate.Session) Before(org.junit.Before)

Example 2 with TokenDAO

use of io.dockstore.webservice.jdbi.TokenDAO in project dockstore by dockstore.

the class UserResource method addUserToDockstoreWorkflows.

@PATCH
@Timed
@UnitOfWork
@Path("/{userId}/workflows")
@ApiOperation(value = "Adds a user to any Dockstore workflows that they should have access to.", authorizations = { @Authorization(value = JWT_SECURITY_DEFINITION_NAME) }, response = Workflow.class, responseContainer = "List")
@Operation(operationId = "addUserToDockstoreWorkflows", description = "Adds the logged-in user to any Dockstore workflows that they should have access to.", security = @SecurityRequirement(name = OPENAPI_JWT_SECURITY_DEFINITION_NAME))
public List<Workflow> addUserToDockstoreWorkflows(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user") @Auth User authUser, @ApiParam(name = "userId", required = true, value = "User to update") @PathParam("userId") @Parameter(name = "userId", in = ParameterIn.PATH, description = "User to update", required = true) long userId, @ApiParam(name = "emptyBody", value = APPEASE_SWAGGER_PATCH) @Parameter(description = APPEASE_SWAGGER_PATCH, name = "emptyBody") String emptyBody) {
    final User user = userDAO.findById(authUser.getId());
    if (user == null || !Objects.equals(userId, user.getId())) {
        throw new CustomWebApplicationException("The user id provided does not match the logged-in user id.", HttpStatus.SC_BAD_REQUEST);
    }
    // Ignore hosted workflows
    List<SourceControl> sourceControls = Arrays.stream(SourceControl.values()).filter(sourceControl -> !Objects.equals(sourceControl, SourceControl.DOCKSTORE)).collect(Collectors.toList());
    List<Token> scTokens = getAndRefreshTokens(user, tokenDAO, client, bitbucketClientID, bitbucketClientSecret).stream().filter(token -> sourceControls.contains(token.getTokenSource().getSourceControl())).collect(Collectors.toList());
    scTokens.forEach(token -> {
        SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(token);
        Map<String, String> gitUrlToRepositoryId = sourceCodeRepo.getWorkflowGitUrl2RepositoryId();
        Set<String> organizations = gitUrlToRepositoryId.values().stream().map(repository -> repository.split("/")[0]).collect(Collectors.toSet());
        organizations.forEach(organization -> {
            List<Workflow> workflowsWithoutuser = workflowDAO.findByOrganizationWithoutUser(token.getTokenSource().getSourceControl(), organization, user);
            workflowsWithoutuser.forEach(workflow -> workflow.addUser(user));
        });
    });
    return convertMyWorkflowsToWorkflow(this.bioWorkflowDAO.findUserBioWorkflows(user.getId()));
}
Also used : Arrays(java.util.Arrays) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ApiParam(io.swagger.annotations.ApiParam) Registry(io.dockstore.common.Registry) SourceCodeRepoFactory(io.dockstore.webservice.helpers.SourceCodeRepoFactory) MediaType(javax.ws.rs.core.MediaType) Matcher(java.util.regex.Matcher) Map(java.util.Map) PAGINATION_LIMIT_TEXT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_LIMIT_TEXT) User(io.dockstore.webservice.core.User) OrganizationUpdateTime(io.dockstore.webservice.core.OrganizationUpdateTime) TokenViews(io.dockstore.webservice.core.TokenViews) Collection(io.dockstore.webservice.core.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Tool(io.dockstore.webservice.core.Tool) Repository(io.dockstore.common.Repository) CloudInstance(io.dockstore.webservice.core.CloudInstance) EntryUpdateTime(io.dockstore.webservice.core.EntryUpdateTime) PATCH(io.swagger.jaxrs.PATCH) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Tag(io.swagger.v3.oas.annotations.tags.Tag) PrivilegeRequest(io.dockstore.webservice.api.PrivilegeRequest) LambdaEvent(io.dockstore.webservice.core.LambdaEvent) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) CachingAuthenticator(io.dropwizard.auth.CachingAuthenticator) PAGINATION_LIMIT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_LIMIT) GET(javax.ws.rs.GET) JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.Constants.JWT_SECURITY_DEFINITION_NAME) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ArrayList(java.util.ArrayList) ServiceDAO(io.dockstore.webservice.jdbi.ServiceDAO) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) Lists(com.google.common.collect.Lists) EntryDAO(io.dockstore.webservice.jdbi.EntryDAO) HttpClient(org.apache.http.client.HttpClient) EventDAO(io.dockstore.webservice.jdbi.EventDAO) ExtendedUserData(io.dockstore.webservice.core.ExtendedUserData) Api(io.swagger.annotations.Api) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) UserDAO(io.dockstore.webservice.jdbi.UserDAO) LinkedHashSet(java.util.LinkedHashSet) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) DeletedUserHelper(io.dockstore.webservice.helpers.DeletedUserHelper) DeletedUsernameDAO(io.dockstore.webservice.jdbi.DeletedUsernameDAO) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) Organization(io.dockstore.webservice.core.Organization) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) MyWorkflows(io.dockstore.webservice.core.database.MyWorkflows) PAGINATION_OFFSET_TEXT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_OFFSET_TEXT) JsonView(com.fasterxml.jackson.annotation.JsonView) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) BioWorkflowDAO(io.dockstore.webservice.jdbi.BioWorkflowDAO) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DefaultValue(javax.ws.rs.DefaultValue) TokenType(io.dockstore.webservice.core.TokenType) OPENAPI_JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.resources.ResourceConstants.OPENAPI_JWT_SECURITY_DEFINITION_NAME) DELETE(javax.ws.rs.DELETE) DeletedUsername(io.dockstore.webservice.core.DeletedUsername) SecurityRequirement(io.swagger.v3.oas.annotations.security.SecurityRequirement) Schema(io.swagger.v3.oas.annotations.media.Schema) Service(io.dockstore.webservice.core.Service) Timestamp(java.sql.Timestamp) Limits(io.dockstore.webservice.api.Limits) Collectors(java.util.stream.Collectors) GoogleHelper(io.dockstore.webservice.helpers.GoogleHelper) Objects(java.util.Objects) Parameter(io.swagger.v3.oas.annotations.Parameter) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) EntryLite(io.dockstore.webservice.core.database.EntryLite) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) PathParam(javax.ws.rs.PathParam) WorkflowMode(io.dockstore.webservice.core.WorkflowMode) Auth(io.dropwizard.auth.Auth) HashMap(java.util.HashMap) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) EntryVersionHelper(io.dockstore.webservice.helpers.EntryVersionHelper) SourceControl(io.dockstore.common.SourceControl) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) APPEASE_SWAGGER_PATCH(io.dockstore.webservice.resources.ResourceConstants.APPEASE_SWAGGER_PATCH) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) SourceControlOrganization(io.dockstore.webservice.core.SourceControlOrganization) PermissionsInterface(io.dockstore.webservice.permissions.PermissionsInterface) Entry(io.dockstore.webservice.core.Entry) LambdaEventDAO(io.dockstore.webservice.jdbi.LambdaEventDAO) PUT(javax.ws.rs.PUT) GitHubSourceCodeRepo(io.dockstore.webservice.helpers.GitHubSourceCodeRepo) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) Hibernate(org.hibernate.Hibernate) User(io.dockstore.webservice.core.User) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) Workflow(io.dockstore.webservice.core.Workflow) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) Token(io.dockstore.webservice.core.Token) SourceControl(io.dockstore.common.SourceControl) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.v3.oas.annotations.Operation) ApiOperation(io.swagger.annotations.ApiOperation) PATCH(io.swagger.jaxrs.PATCH) APPEASE_SWAGGER_PATCH(io.dockstore.webservice.resources.ResourceConstants.APPEASE_SWAGGER_PATCH)

Example 3 with TokenDAO

use of io.dockstore.webservice.jdbi.TokenDAO in project dockstore by dockstore.

the class UserResource method getGitRepositoryMap.

/**
 * For a given user and git registry, retrieve a map of git url to repository path
 * @param user
 * @param gitRegistry
 * @return mapping of git url to repository path
 */
private Map<String, String> getGitRepositoryMap(User user, SourceControl gitRegistry) {
    List<Token> scTokens = getAndRefreshTokens(user, tokenDAO, client, bitbucketClientID, bitbucketClientSecret).stream().filter(token -> Objects.equals(token.getTokenSource().getSourceControl(), gitRegistry)).collect(Collectors.toList());
    if (scTokens.size() > 0) {
        Token scToken = scTokens.get(0);
        SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(scToken);
        return sourceCodeRepo.getWorkflowGitUrl2RepositoryId();
    } else {
        return new HashMap<>();
    }
}
Also used : Arrays(java.util.Arrays) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ApiParam(io.swagger.annotations.ApiParam) Registry(io.dockstore.common.Registry) SourceCodeRepoFactory(io.dockstore.webservice.helpers.SourceCodeRepoFactory) MediaType(javax.ws.rs.core.MediaType) Matcher(java.util.regex.Matcher) Map(java.util.Map) PAGINATION_LIMIT_TEXT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_LIMIT_TEXT) User(io.dockstore.webservice.core.User) OrganizationUpdateTime(io.dockstore.webservice.core.OrganizationUpdateTime) TokenViews(io.dockstore.webservice.core.TokenViews) Collection(io.dockstore.webservice.core.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Tool(io.dockstore.webservice.core.Tool) Repository(io.dockstore.common.Repository) CloudInstance(io.dockstore.webservice.core.CloudInstance) EntryUpdateTime(io.dockstore.webservice.core.EntryUpdateTime) PATCH(io.swagger.jaxrs.PATCH) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Tag(io.swagger.v3.oas.annotations.tags.Tag) PrivilegeRequest(io.dockstore.webservice.api.PrivilegeRequest) LambdaEvent(io.dockstore.webservice.core.LambdaEvent) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) CachingAuthenticator(io.dropwizard.auth.CachingAuthenticator) PAGINATION_LIMIT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_LIMIT) GET(javax.ws.rs.GET) JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.Constants.JWT_SECURITY_DEFINITION_NAME) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ArrayList(java.util.ArrayList) ServiceDAO(io.dockstore.webservice.jdbi.ServiceDAO) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) Lists(com.google.common.collect.Lists) EntryDAO(io.dockstore.webservice.jdbi.EntryDAO) HttpClient(org.apache.http.client.HttpClient) EventDAO(io.dockstore.webservice.jdbi.EventDAO) ExtendedUserData(io.dockstore.webservice.core.ExtendedUserData) Api(io.swagger.annotations.Api) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) UserDAO(io.dockstore.webservice.jdbi.UserDAO) LinkedHashSet(java.util.LinkedHashSet) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) DeletedUserHelper(io.dockstore.webservice.helpers.DeletedUserHelper) DeletedUsernameDAO(io.dockstore.webservice.jdbi.DeletedUsernameDAO) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) Organization(io.dockstore.webservice.core.Organization) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) MyWorkflows(io.dockstore.webservice.core.database.MyWorkflows) PAGINATION_OFFSET_TEXT(io.dockstore.webservice.resources.ResourceConstants.PAGINATION_OFFSET_TEXT) JsonView(com.fasterxml.jackson.annotation.JsonView) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) BioWorkflowDAO(io.dockstore.webservice.jdbi.BioWorkflowDAO) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DefaultValue(javax.ws.rs.DefaultValue) TokenType(io.dockstore.webservice.core.TokenType) OPENAPI_JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.resources.ResourceConstants.OPENAPI_JWT_SECURITY_DEFINITION_NAME) DELETE(javax.ws.rs.DELETE) DeletedUsername(io.dockstore.webservice.core.DeletedUsername) SecurityRequirement(io.swagger.v3.oas.annotations.security.SecurityRequirement) Schema(io.swagger.v3.oas.annotations.media.Schema) Service(io.dockstore.webservice.core.Service) Timestamp(java.sql.Timestamp) Limits(io.dockstore.webservice.api.Limits) Collectors(java.util.stream.Collectors) GoogleHelper(io.dockstore.webservice.helpers.GoogleHelper) Objects(java.util.Objects) Parameter(io.swagger.v3.oas.annotations.Parameter) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) EntryLite(io.dockstore.webservice.core.database.EntryLite) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) PathParam(javax.ws.rs.PathParam) WorkflowMode(io.dockstore.webservice.core.WorkflowMode) Auth(io.dropwizard.auth.Auth) HashMap(java.util.HashMap) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) EntryVersionHelper(io.dockstore.webservice.helpers.EntryVersionHelper) SourceControl(io.dockstore.common.SourceControl) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) APPEASE_SWAGGER_PATCH(io.dockstore.webservice.resources.ResourceConstants.APPEASE_SWAGGER_PATCH) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) SourceControlOrganization(io.dockstore.webservice.core.SourceControlOrganization) PermissionsInterface(io.dockstore.webservice.permissions.PermissionsInterface) Entry(io.dockstore.webservice.core.Entry) LambdaEventDAO(io.dockstore.webservice.jdbi.LambdaEventDAO) PUT(javax.ws.rs.PUT) GitHubSourceCodeRepo(io.dockstore.webservice.helpers.GitHubSourceCodeRepo) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) Hibernate(org.hibernate.Hibernate) HashMap(java.util.HashMap) Token(io.dockstore.webservice.core.Token) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface)

Example 4 with TokenDAO

use of io.dockstore.webservice.jdbi.TokenDAO in project dockstore by dockstore.

the class SamPermissionsImplTest method setup.

@Before
public void setup() {
    ownerPolicy = new AccessPolicyResponseEntry();
    ownerPolicy.setPolicyName(SamConstants.OWNER_POLICY);
    AccessPolicyMembership accessPolicyMembership = new AccessPolicyMembership();
    accessPolicyMembership.setRoles(Collections.singletonList(SamConstants.OWNER_POLICY));
    accessPolicyMembership.setMemberEmails(Collections.singletonList("jdoe@ucsc.edu"));
    ownerPolicy.setPolicy(accessPolicyMembership);
    writerPolicy = new AccessPolicyResponseEntry();
    writerPolicy.setPolicyName(SamConstants.WRITE_POLICY);
    AccessPolicyMembership writerMembership = new AccessPolicyMembership();
    writerMembership.setRoles(Collections.singletonList(SamConstants.WRITE_POLICY));
    writerMembership.setMemberEmails(Collections.singletonList(JANE_DOE_GMAIL_COM));
    writerPolicy.setPolicy(writerMembership);
    AccessPolicyResponseEntry readerPolicy = new AccessPolicyResponseEntry();
    readerPolicy.setPolicyName(SamConstants.READ_POLICY);
    AccessPolicyMembership readerMembership = new AccessPolicyMembership();
    readerMembership.setRoles(Collections.singletonList(SamConstants.READ_POLICY));
    readerMembership.setMemberEmails(Collections.singletonList(JANE_DOE_GMAIL_COM));
    readerPolicy.setPolicy(readerMembership);
    TokenDAO tokenDAO = Mockito.mock(TokenDAO.class);
    DockstoreWebserviceConfiguration configMock = Mockito.mock(DockstoreWebserviceConfiguration.class);
    when(configMock.getSamConfiguration()).thenReturn(new DockstoreWebserviceConfiguration.SamConfiguration());
    samPermissionsImpl = Mockito.spy(new SamPermissionsImpl(tokenDAO, configMock));
    doReturn(Optional.of("my token")).when(samPermissionsImpl).googleAccessToken(userMock);
    doReturn(Mockito.mock(Token.class)).when(samPermissionsImpl).googleToken(userMock);
    resourcesApiMock = Mockito.mock(ResourcesApi.class);
    ApiClient apiClient = Mockito.mock(ApiClient.class);
    when(apiClient.escapeString(ArgumentMatchers.anyString())).thenAnswer(invocation -> invocation.getArgument(0));
    when(resourcesApiMock.getApiClient()).thenReturn(apiClient);
    when(samPermissionsImpl.getResourcesApi(userMock)).thenReturn(resourcesApiMock);
    workflowInstance = Mockito.mock(Workflow.class);
    when(workflowInstance.getWorkflowPath()).thenReturn("foo");
    ownerPermission = new Permission();
    ownerPermission.setEmail("jdoe@ucsc.edu");
    ownerPermission.setRole(Role.OWNER);
    Assert.assertThat(samPermissionsImpl.accessPolicyResponseEntryToUserPermissions(Collections.singletonList(ownerPolicy)), CoreMatchers.is(Collections.singletonList(ownerPermission)));
    writerPermission = new Permission();
    writerPermission.setEmail(JANE_DOE_GMAIL_COM);
    writerPermission.setRole(Role.WRITER);
    readerPermission = new Permission();
    readerPermission.setEmail(JANE_DOE_GMAIL_COM);
    readerPermission.setRole(Role.READER);
    AccessPolicyMembership readerAccessPolicyMembership = new AccessPolicyMembership();
    readerAccessPolicyResponseEntry = new AccessPolicyResponseEntry();
    readerAccessPolicyResponseEntry.setPolicy(readerAccessPolicyMembership);
    readerAccessPolicyResponseEntry.setPolicyName(SamConstants.READ_POLICY);
    readerAccessPolicyResponseEntry.getPolicy().addRolesItem(SamConstants.READ_POLICY);
    readerAccessPolicyResponseEntry.getPolicy().addMemberEmailsItem(JANE_DOE_GMAIL_COM);
    final User.Profile profile = new User.Profile();
    profile.email = JANE_DOE_GMAIL_COM;
    final Map<String, User.Profile> map = new HashMap<>();
    map.put(TokenType.GOOGLE_COM.toString(), profile);
    when(userMock.getUserProfiles()).thenReturn(map);
}
Also used : User(io.dockstore.webservice.core.User) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) HashMap(java.util.HashMap) Workflow(io.dockstore.webservice.core.Workflow) Token(io.dockstore.webservice.core.Token) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(io.swagger.sam.client.ApiClient) AccessPolicyMembership(io.swagger.sam.client.model.AccessPolicyMembership) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) AccessPolicyResponseEntry(io.swagger.sam.client.model.AccessPolicyResponseEntry) Permission(io.dockstore.webservice.permissions.Permission) ResourcesApi(io.swagger.sam.client.api.ResourcesApi) Before(org.junit.Before)

Example 5 with TokenDAO

use of io.dockstore.webservice.jdbi.TokenDAO in project dockstore by dockstore.

the class AdvancedIndexingBenchmarkIT method testCreate10000Tools.

@Test
public void testCreate10000Tools() {
    this.sessionFactory = application.getHibernate().getSessionFactory();
    try {
        Transaction transaction = this.sessionFactory.openSession().getTransaction();
        transaction.begin();
        TokenDAO tokenDAO = new TokenDAO(sessionFactory);
        User user = new User();
        user.setIsAdmin(true);
        user.setUsername("travistest");
        Token token = new Token();
        token.setUserId(1);
        token.setUsername("travistest");
        token.setContent("iamafakedockstoretoken");
        token.setTokenSource(TokenType.DOCKSTORE);
        tokenDAO.create(token);
        Token token2 = new Token();
        token2.setUserId(1);
        token2.setUsername("travistest");
        token2.setContent("iamafakegithubtoken");
        token2.setTokenSource(TokenType.GITHUB_COM);
        tokenDAO.create(token2);
        UserDAO userDAO = new UserDAO(sessionFactory);
        userDAO.create(user);
        transaction.commit();
    } finally {
        session.close();
    }
    session = application.getHibernate().getSessionFactory().openSession();
    ManagedSessionContext.bind(session);
    for (int i = 0; i < TOOL_COUNT; i++) {
        createTool();
    }
    Response response = client.target("http://localhost:" + SUPPORT.getLocalPort() + "/containers/published").request().get();
    List<Tool> tools = response.readEntity(new GenericType<List<Tool>>() {
    });
    int actualToolCount = tools.size();
    assertEquals("Supposed to have " + TOOL_COUNT + " tools.  Instead got " + actualToolCount + " tools.", actualToolCount, TOOL_COUNT);
    LOGGER.error("Amount of tools created: " + String.valueOf(actualToolCount));
    for (Long indexTime : indexTimes) {
        LOGGER.error(String.valueOf(indexTime));
    }
}
Also used : Response(javax.ws.rs.core.Response) User(io.dockstore.webservice.core.User) Transaction(org.hibernate.Transaction) UserDAO(io.dockstore.webservice.jdbi.UserDAO) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Token(io.dockstore.webservice.core.Token) ArrayList(java.util.ArrayList) List(java.util.List) Tool(io.dockstore.webservice.core.Tool) Test(org.junit.Test) BenchmarkTest(io.dockstore.common.BenchmarkTest) ToolTest(io.dockstore.common.ToolTest)

Aggregations

TokenDAO (io.dockstore.webservice.jdbi.TokenDAO)7 User (io.dockstore.webservice.core.User)5 Token (io.dockstore.webservice.core.Token)4 DockstoreWebserviceConfiguration (io.dockstore.webservice.DockstoreWebserviceConfiguration)3 OrganizationUser (io.dockstore.webservice.core.OrganizationUser)3 Tool (io.dockstore.webservice.core.Tool)3 Workflow (io.dockstore.webservice.core.Workflow)3 UserDAO (io.dockstore.webservice.jdbi.UserDAO)3 HashMap (java.util.HashMap)3 SessionFactory (org.hibernate.SessionFactory)3 Timed (com.codahale.metrics.annotation.Timed)2 JsonView (com.fasterxml.jackson.annotation.JsonView)2 Lists (com.google.common.collect.Lists)2 Registry (io.dockstore.common.Registry)2 Repository (io.dockstore.common.Repository)2 SourceControl (io.dockstore.common.SourceControl)2 JWT_SECURITY_DEFINITION_NAME (io.dockstore.webservice.Constants.JWT_SECURITY_DEFINITION_NAME)2 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)2 Limits (io.dockstore.webservice.api.Limits)2 PrivilegeRequest (io.dockstore.webservice.api.PrivilegeRequest)2