Search in sources :

Example 96 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class UsersResource method findById.

@GET
@Path("{userId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find User by Id.", response = UserProfileDTO.class)
public Response findById(@PathParam("userId") Integer userId, @Context UriInfo uriInfo, @Context SecurityContext sc) throws UserException {
    Users user = jWTHelper.getUserPrincipal(sc);
    BbcGroup adminGroup = bbcGroupFacade.findByGroupName("HOPS_ADMIN");
    if (!Objects.equals(user.getUid(), userId) && !user.getBbcGroupCollection().contains(adminGroup)) {
        throw new UserException(RESTCodes.UserErrorCode.ACCESS_CONTROL, Level.SEVERE);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.USERS);
    UserProfileDTO userDTO = usersBuilder.build(uriInfo, resourceRequest, userId);
    return Response.ok().entity(userDTO).build();
}
Also used : BbcGroup(io.hops.hopsworks.persistence.entity.user.BbcGroup) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 97 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class TestCommitBuilder method testBuildPopulatedOffsetAndLimit.

@Test
public void testBuildPopulatedOffsetAndLimit() throws Exception {
    // arrange
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.COMMITS);
    resourceRequest.setOffset(0);
    resourceRequest.setLimit(0);
    resourceRequest.setSort(new HashSet<SortBy>());
    resourceRequest.setFilter(new HashSet<FilterBy>());
    // act
    CommitDTO commitDTO = commitBuilder.build(mockUriInfo, resourceRequest, project, featuregroup);
    // assert
    verify(featureGroupCommitController).getCommitDetails(featuregroup.getId(), 0, 0, resourceRequest.getSort(), resourceRequest.getFilter());
    Assert.assertEquals(0, commitDTO.getCount().intValue());
}
Also used : ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Test(org.junit.Test)

Example 98 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class UsersResource method findAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all users.", response = UserDTO.class)
public Response findAll(@BeanParam Pagination pagination, @BeanParam UsersBeanParam usersBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws UserException {
    if (!settings.isUserSearchEnabled()) {
        throw new UserException(RESTCodes.UserErrorCode.USER_SEARCH_NOT_ALLOWED, Level.FINE);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.USERS);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(usersBeanParam.getSortBySet());
    resourceRequest.setFilter(usersBeanParam.getFilter());
    UserDTO userDTO = usersBuilder.buildItems(uriInfo, resourceRequest);
    return Response.ok().entity(userDTO).build();
}
Also used : UserException(io.hops.hopsworks.exceptions.UserException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 99 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class GitResource method fileCheckout.

@ApiOperation(value = "Execute git checkout --filename. The final execution message will " + "contain the list of files in the status. If some of the files in the argument are present in the final " + "execution message then they failed to be checkout out", response = GitOpExecutionDTO.class)
@POST
@Path("/repository/{repositoryId}/file")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response fileCheckout(@Context UriInfo uriInfo, @PathParam("repositoryId") Integer repositoryId, @Context SecurityContext sc, GitFileCheckout files, @BeanParam ExecutionBeanParam executionBeanParam) throws GitOpException, HopsSecurityException {
    Users hopsworksUser = jWTHelper.getUserPrincipal(sc);
    GitOpExecution execution = gitController.fileCheckout(project, hopsworksUser, repositoryId, files.getFiles());
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXECUTION);
    resourceRequest.setExpansions(executionBeanParam.getExpansions().getResources());
    GitOpExecutionDTO dto = executionBuilder.build(uriInfo, resourceRequest, execution);
    return Response.ok().entity(dto).build();
}
Also used : GitOpExecutionDTO(io.hops.hopsworks.api.git.execution.GitOpExecutionDTO) GitOpExecution(io.hops.hopsworks.persistence.entity.git.GitOpExecution) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 100 with ResourceRequest

use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.

the class GitResource method gitRepository.

@ApiOperation(value = "Get a repository with a particular Id", response = GitRepositoryDTO.class)
@GET
@Path("/repository/{repositoryId}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.GIT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response gitRepository(@PathParam("repositoryId") Integer repositoryId, @Context SecurityContext sc, @Context UriInfo uriInfo, @BeanParam RepositoryBeanParam repositoryBeanParam) throws GitOpException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.REPOSITORY);
    resourceRequest.setExpansions(repositoryBeanParam.getExpansions().getResources());
    GitRepository gitRepository = commandConfigurationValidator.verifyRepository(project, repositoryId);
    GitRepositoryDTO dto = gitRepositoryBuilder.build(uriInfo, resourceRequest, project, gitRepository);
    return Response.ok().entity(dto).build();
}
Also used : GitRepository(io.hops.hopsworks.persistence.entity.git.GitRepository) GitRepositoryDTO(io.hops.hopsworks.api.git.repository.GitRepositoryDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)171 ApiOperation (io.swagger.annotations.ApiOperation)163 Produces (javax.ws.rs.Produces)157 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)151 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)127 GET (javax.ws.rs.GET)107 Path (javax.ws.rs.Path)99 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)94 Users (io.hops.hopsworks.persistence.entity.user.Users)75 Consumes (javax.ws.rs.Consumes)37 POST (javax.ws.rs.POST)30 PUT (javax.ws.rs.PUT)27 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)20 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)17 AlertException (io.hops.hopsworks.exceptions.AlertException)14 Project (io.hops.hopsworks.persistence.entity.project.Project)14 UriBuilder (javax.ws.rs.core.UriBuilder)12 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)11 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)11 HashMap (java.util.HashMap)9